feat: add fallback response handling and UI indicators
- Introduced a new `is_fallback` property to track when responses are generated without knowledge base matches. - Updated the chat components to display fallback hints and indicators in the UI, enhancing user awareness of fallback responses. - Added translations for fallback hints in multiple languages, improving accessibility for diverse users. - Modified backend logic to emit fallback status in response events, ensuring consistent handling across the application. These changes improve the user experience by providing clear feedback on fallback responses, enhancing the overall interaction with the chat system.
This commit is contained in:
@@ -1709,8 +1709,9 @@ func (s *sessionService) consumeFallbackStream(
|
||||
Type: types.EventType(event.EventAgentFinalAnswer),
|
||||
SessionID: chatManage.SessionID,
|
||||
Data: event.AgentFinalAnswerData{
|
||||
Content: response.Content,
|
||||
Done: response.Done,
|
||||
Content: response.Content,
|
||||
Done: response.Done,
|
||||
IsFallback: true,
|
||||
},
|
||||
}); err != nil {
|
||||
logger.Errorf(ctx, "Failed to emit fallback answer chunk event: %v", err)
|
||||
@@ -1745,8 +1746,9 @@ func (s *sessionService) emitFallbackAnswer(ctx context.Context, chatManage *typ
|
||||
Type: types.EventType(event.EventAgentFinalAnswer),
|
||||
SessionID: chatManage.SessionID,
|
||||
Data: event.AgentFinalAnswerData{
|
||||
Content: content,
|
||||
Done: true,
|
||||
Content: content,
|
||||
Done: true,
|
||||
IsFallback: true,
|
||||
},
|
||||
}); err != nil {
|
||||
logger.Errorf(ctx, "Failed to emit fallback answer event: %v", err)
|
||||
|
||||
@@ -183,8 +183,9 @@ type AgentReferencesData struct {
|
||||
|
||||
// AgentFinalAnswerData represents final answer streaming data
|
||||
type AgentFinalAnswerData struct {
|
||||
Content string `json:"content"`
|
||||
Done bool `json:"done"`
|
||||
Content string `json:"content"`
|
||||
Done bool `json:"done"`
|
||||
IsFallback bool `json:"is_fallback,omitempty"` // True when response is a fallback (no knowledge base match)
|
||||
}
|
||||
|
||||
// AgentReflectionData represents agent reflection data
|
||||
|
||||
@@ -291,6 +291,9 @@ func (h *AgentStreamHandler) handleFinalAnswer(ctx context.Context, evt event.Ev
|
||||
|
||||
// Accumulate final answer locally for assistant message (database)
|
||||
h.finalAnswer += data.Content
|
||||
if data.IsFallback {
|
||||
h.assistantMessage.IsFallback = true
|
||||
}
|
||||
|
||||
// Calculate duration if done
|
||||
var metadata map[string]interface{}
|
||||
@@ -308,6 +311,9 @@ func (h *AgentStreamHandler) handleFinalAnswer(ctx context.Context, evt event.Ev
|
||||
"event_id": evt.ID,
|
||||
}
|
||||
}
|
||||
if data.IsFallback {
|
||||
metadata["is_fallback"] = true
|
||||
}
|
||||
h.mu.Unlock()
|
||||
|
||||
// Append this chunk to stream (frontend will accumulate by event ID)
|
||||
|
||||
@@ -406,6 +406,9 @@ func (h *Handler) executeNormalModeQA(reqCtx *qaRequestContext, generateTitle bo
|
||||
return nil
|
||||
}
|
||||
streamCtx.assistantMessage.Content += data.Content
|
||||
if data.IsFallback {
|
||||
streamCtx.assistantMessage.IsFallback = true
|
||||
}
|
||||
if data.Done {
|
||||
// Prevent duplicate completion handling
|
||||
if completionHandled {
|
||||
|
||||
@@ -78,6 +78,8 @@ type Message struct {
|
||||
MentionedItems MentionedItems `json:"mentioned_items,omitempty" gorm:"type:jsonb,column:mentioned_items"`
|
||||
// Whether message generation is complete
|
||||
IsCompleted bool `json:"is_completed"`
|
||||
// Whether this response is a fallback (no knowledge base match found)
|
||||
IsFallback bool `json:"is_fallback,omitempty"`
|
||||
// Message creation timestamp
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// Last update timestamp
|
||||
|
||||
Reference in New Issue
Block a user