Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat: 增加流式响应类型和工具调用支持

wizardchen72a3cbb0baa2
diff --git a/client/session.go b/client/session.go
index d9979d8e5..c6487167c 100644
--- a/client/session.go
+++ b/client/session.go
@@ -191,20 +191,45 @@ type KnowledgeQARequest struct {
DisableTitle bool `json:"disable_title"` // Whether to disable auto title generation
}
+// LLMToolCall represents a function/tool call from the LLM
+type LLMToolCall struct {
+ ID string `json:"id"`
+ Type string `json:"type"` // "function"
+ Function FunctionCall `json:"function"`
+}
+
+// FunctionCall represents the function details
+type FunctionCall struct {
+ Name string `json:"name"`
+ Arguments string `json:"arguments"` // JSON string
+}
+
type ResponseType string
const (
- ResponseTypeAnswer ResponseType = "answer"
- ResponseTypeReferences ResponseType = "references"
+ ResponseTypeAnswer ResponseType = "answer"
+ ResponseTypeReferences ResponseType = "references"
+ ResponseTypeThinking ResponseType = "thinking"
+ ResponseTypeToolCall ResponseType = "tool_call"
+ ResponseTypeToolResult ResponseType = "tool_result"
+ ResponseTypeError ResponseType = "error"
+ ResponseTypeReflection ResponseType = "reflection"
+ ResponseTypeSessionTitle ResponseType = "session_title"
+ ResponseTypeAgentQuery ResponseType = "agent_query"
+ ResponseTypeComplete ResponseType = "complete"
)
// StreamResponse streaming response
type StreamResponse struct {
- ID string `json:"id"` // Unique identifier
- ResponseType ResponseType `json:"response_type"` // Response type
- Content string `json:"content"` // Current content fragment
- Done bool `json:"done"` // Whether completed
- KnowledgeReferences []*SearchResult `json:"knowledge_references"` // Knowledge references
+ ID string `json:"id"` // Unique identifier
+ ResponseType ResponseType `json:"response_type"` // Response type
+ Content string `json:"content"` // Current content fragment
+ Done bool `json:"done"` // Whether completed
+ KnowledgeReferences []*SearchResult `json:"knowledge_references,omitempty"` // Knowledge references
+ SessionID string `json:"session_id,omitempty"` // Session ID (for agent_query event)
+ AssistantMessageID string `json:"assistant_message_id,omitempty"` // Assistant Message ID (for agent_query event)
+ ToolCalls []LLMToolCall `json:"tool_calls,omitempty"` // Tool calls for streaming (partial)
+ Data map[string]interface{} `json:"data,omitempty"` // Additional metadata for enhanced display
}
// KnowledgeQAStream knowledge Q&A streaming API
diff --git a/internal/handler/session/helpers.go b/internal/handler/session/helpers.go
index b1e76d77c..81c652064 100644
--- a/internal/handler/session/helpers.go
+++ b/internal/handler/session/helpers.go
@@ -59,8 +59,19 @@ func buildStreamResponse(evt interfaces.StreamEvent, requestID string) *types.St
// Special handling for references event
if evt.Type == types.ResponseTypeReferences {
- if refs, ok := evt.Data["references"].(types.References); ok {
+ refsData := evt.Data["references"]
+ logger.GetLogger(context.Background()).Info("buildStreamResponse references event",
+ "refsData_type", fmt.Sprintf("%T", refsData),
+ "refsData", refsData)
+ if refs, ok := refsData.(types.References); ok {
+ logger.GetLogger(context.Background()).Info("buildStreamResponse: matched types.References")
response.KnowledgeReferences = refs
+ } else if refs, ok := refsData.([]*types.SearchResult); ok {
+ logger.GetLogger(context.Background()).Info("buildStreamResponse: matched []*types.SearchResult")
+ response.KnowledgeReferences = types.References(refs)
+ } else {
+ logger.GetLogger(context.Background()).Warn("buildStreamResponse: references type assertion failed",
+ "actual_type", fmt.Sprintf("%T", refsData))
}
}