Add instruction fields to knowledge base configuration
This commit is contained in:
@@ -47,9 +47,17 @@ const (
|
||||
"5. Output ONLY the extracted text content. Do NOT include any HTML tags, reasoning, or unrelated comments.\n" +
|
||||
"6. If there is absolutely no recognizable text content in the image, reply ONLY with: No text content.\n" +
|
||||
"</instructions>"
|
||||
vlmCaptionPrompt = "Provide a brief and concise description of the main content of the image in Chinese"
|
||||
)
|
||||
|
||||
func buildVLMCaptionPrompt(ctx context.Context, cfg types.VLMConfig) string {
|
||||
language := strings.TrimSpace(cfg.DescriptionLanguage)
|
||||
if language == "" {
|
||||
language = types.LanguageNameFromContext(ctx)
|
||||
}
|
||||
prompt := fmt.Sprintf("Provide a brief and concise description of the main content of the image in %s.", language)
|
||||
return types.AppendCustomPromptInstructions(prompt, cfg.CustomInstructions, "image_description")
|
||||
}
|
||||
|
||||
// ImageMultimodalService handles image:multimodal asynq tasks.
|
||||
// It reads images from storage (via FileService for provider:// URLs),
|
||||
// performs OCR and VLM caption, and creates child chunks.
|
||||
@@ -243,6 +251,7 @@ func (s *ImageMultimodalService) Handle(ctx context.Context, task *asynq.Task) e
|
||||
} else {
|
||||
imgOut["ocr_prompt"] = "default"
|
||||
}
|
||||
prompt = types.AppendCustomPromptInstructions(prompt, vlmCfg.CustomInstructions, "image_ocr")
|
||||
|
||||
ocrText, ocrErr := vlmModel.Predict(ctx, [][]byte{imgBytes}, prompt)
|
||||
if ocrErr != nil {
|
||||
@@ -262,7 +271,7 @@ func (s *ImageMultimodalService) Handle(ctx context.Context, task *asynq.Task) e
|
||||
}
|
||||
}
|
||||
|
||||
caption, capErr := vlmModel.Predict(ctx, [][]byte{imgBytes}, vlmCaptionPrompt)
|
||||
caption, capErr := vlmModel.Predict(ctx, [][]byte{imgBytes}, buildVLMCaptionPrompt(ctx, vlmCfg))
|
||||
if capErr != nil {
|
||||
logger.Warnf(ctx, "[ImageMultimodal] Caption failed for %s: %v", payload.ImageURL, capErr)
|
||||
imgOut["caption_error"] = capErr.Error()
|
||||
|
||||
Reference in New Issue
Block a user