refactor(chat): enhance follow-up handling for previous image/document context

Update the classification logic for follow-up questions to include reasoning about previously described images or documents. Ensure that follow-up queries referencing earlier attachments are correctly identified and processed without triggering unnecessary knowledge base searches. This change improves the model's ability to maintain context and respond accurately to user inquiries related to past interactions.
This commit is contained in:
wizardchen
2026-07-16 16:29:32 +08:00
committed by lyingbug
parent ceb4d1a310
commit 92ceb3bd7d
3 changed files with 21 additions and 625 deletions
@@ -151,8 +151,19 @@ func loadAndProcessHistory(
h.Query = message.Content
}
h.CreateAt = message.CreatedAt
if desc := extractImageCaptions(message.Images); desc != "" && message.RenderedContent == "" {
h.Query += "\n\n[用户上传图片内容]\n" + desc
// When RenderedContent is absent (e.g. the pure-chat, non-RAG path
// and the search-nothing fallback path never persist it), replay the
// previous turn's image captions and attachment content from the
// stored message so the model retains a textual reference to them.
// When RenderedContent is present it already carries this
// augmentation, so we must not double-append.
if message.RenderedContent == "" {
if desc := extractImageCaptions(message.Images); desc != "" {
h.Query += "\n\n[用户上传图片内容]\n" + desc
}
if len(message.Attachments) > 0 {
h.Query += message.Attachments.BuildPrompt()
}
}
} else {
h.Answer = regThinkTags.ReplaceAllString(message.Content, "")