feat(image-multimodal): add task enqueuing for question generation based on image knowledge

- Introduced a new task enqueuer in the ImageMultimodalService to handle question generation for image knowledge.
- Implemented logic to enqueue question generation tasks when valid captions or OCR content are available, enhancing the knowledge base's interactivity.
- Updated image reference handling to ensure markdown URLs are correctly formatted, accommodating filenames with spaces.
- Enhanced regex pattern in image resolver to support filenames with spaces, improving image processing accuracy.
This commit is contained in:
wizardchen
2026-03-25 20:58:51 +08:00
committed by lyingbug
parent 1960fc2d90
commit 23290efcec
3 changed files with 60 additions and 3 deletions
@@ -77,14 +77,16 @@ func imageToResult(fileName string, data []byte) *types.ReadResult {
fileName = "image.png"
}
refPath := "images/" + fileName
// Encode spaces so the markdown URL is valid and matches the regex in ResolveAndStore.
safeRef := strings.ReplaceAll(refPath, " ", "%20")
mime := http.DetectContentType(data)
return &types.ReadResult{
MarkdownContent: fmt.Sprintf("![%s](%s)", fileName, refPath),
MarkdownContent: fmt.Sprintf("![%s](%s)", fileName, safeRef),
ImageRefs: []types.ImageRef{
{
Filename: fileName,
OriginalRef: refPath,
OriginalRef: safeRef,
MimeType: mime,
ImageData: data,
},
@@ -104,7 +104,9 @@ func (r *ImageResolver) ResolveAndStore(
// Process each image reference found in the markdown.
// The URL group supports one level of balanced parentheses so that URLs
// like https://example.com/item_(abc)/123 are captured in full.
imgPattern := regexp.MustCompile(`!\[(.*?)\]\(([^()\s]*(?:\([^)]*\)[^()\s]*)*)\)`)
// Allow spaces in URLs (exclude only parens and newlines) to handle
// filenames with spaces, e.g. "images/第 1 页.jpg".
imgPattern := regexp.MustCompile(`!\[(.*?)\]\(([^()\n]*(?:\([^)]*\)[^()\n]*)*)\)`)
matches := imgPattern.FindAllStringSubmatchIndex(markdown, -1)
// Process in reverse order to preserve positions when replacing