feat: enhance multimodal image processing and session management

- Updated configuration to support three tasks in the assistant's prompt: rewriting questions, classifying intent for knowledge base retrieval, and analyzing attached images.
- Implemented backend functionality to update image descriptions in user messages, ensuring that image context is preserved across conversation history.
- Modified session handling to return complete session data after updates, improving the accuracy of session information provided to users.
- Enhanced the chat pipeline to include detailed image descriptions and manage image captions effectively, enriching user interactions with visual content.

These improvements significantly enhance the application's multimodal capabilities, providing a more robust and user-friendly experience when handling image-based queries.
This commit is contained in:
wizardchen
2026-03-12 13:17:47 +08:00
parent bc2cb96d70
commit 4eed96f901
15 changed files with 319 additions and 65 deletions
+4 -2
View File
@@ -62,8 +62,9 @@ type ChatManage struct {
FAQScoreBoost float64 `json:"-"` // Score multiplier for FAQ results
// Image support for multimodal chat
UserMessageID string `json:"-"` // User message ID for updating image captions after rewrite
Images []string `json:"-"` // Image URLs for MultiContent in current user message
ImageOCRText string `json:"-"` // Image description/OCR text generated by VLM (used as fallback for non-vision models)
ImageDescription string `json:"-"` // Image description (visual details + OCR text) generated by VLM (used as fallback for non-vision models)
VLMModelID string `json:"-"` // Agent-configured VLM model ID for image analysis
ChatModelSupportsVision bool `json:"-"` // Whether the chat model accepts multimodal/image input
SkipKBSearch bool `json:"-"` // Set by rewrite intent classification: true = skip KB retrieval
@@ -136,8 +137,9 @@ func (c *ChatManage) Clone() *ChatManage {
FAQPriorityEnabled: c.FAQPriorityEnabled,
FAQDirectAnswerThreshold: c.FAQDirectAnswerThreshold,
FAQScoreBoost: c.FAQScoreBoost,
UserMessageID: c.UserMessageID,
Images: append([]string(nil), c.Images...),
ImageOCRText: c.ImageOCRText,
ImageDescription: c.ImageDescription,
VLMModelID: c.VLMModelID,
ChatModelSupportsVision: c.ChatModelSupportsVision,
SkipKBSearch: c.SkipKBSearch,
+5
View File
@@ -29,6 +29,9 @@ type MessageService interface {
// UpdateMessage updates a message
UpdateMessage(ctx context.Context, message *types.Message) error
// UpdateMessageImages updates only the images JSONB column for a message.
UpdateMessageImages(ctx context.Context, sessionID, messageID string, images types.MessageImages) error
// DeleteMessage deletes a message
DeleteMessage(ctx context.Context, sessionID string, id string) error
@@ -66,6 +69,8 @@ type MessageRepository interface {
) ([]*types.Message, error)
// UpdateMessage updates a message
UpdateMessage(ctx context.Context, message *types.Message) error
// UpdateMessageImages updates only the images JSONB column for a message
UpdateMessageImages(ctx context.Context, sessionID, messageID string, images types.MessageImages) error
// DeleteMessage deletes a message
DeleteMessage(ctx context.Context, sessionID string, id string) error
// GetFirstMessageOfUser gets the first message of a user
+2 -2
View File
@@ -44,7 +44,7 @@ type SessionService interface {
session *types.Session, query string, knowledgeBaseIDs []string, knowledgeIDs []string,
assistantMessageID string, summaryModelID string, webSearchEnabled bool, eventBus *event.EventBus,
customAgent *types.CustomAgent, enableMemory bool,
imageURLs []string, imageOCRText string,
imageURLs []string, imageDescription string, userMessageID string,
) error
// KnowledgeQAByEvent performs knowledge-based question answering by event
KnowledgeQAByEvent(ctx context.Context, chatManage *types.ChatManage, eventList []types.EventType) error
@@ -66,7 +66,7 @@ type SessionService interface {
customAgent *types.CustomAgent,
knowledgeBaseIDs []string,
knowledgeIDs []string,
imageURLs []string, imageOCRText string,
imageURLs []string, imageDescription string, userMessageID string,
) error
// ClearContext clears the LLM context for a session
ClearContext(ctx context.Context, sessionID string) error