refactor: consolidate QA request handling and improve session service interface
- Introduced a new `QARequest` type to streamline parameters for KnowledgeQA and AgentQA service calls, replacing multiple parameters with a single structured request. - Updated the `KnowledgeQA` and `AgentQA` methods in the session service interface to accept the new `QARequest` type, enhancing clarity and maintainability. - Refactored the request parsing logic to utilize the new `buildQARequest` method, improving code organization and reducing redundancy. - Implemented a new `resolveAgent` method to simplify custom agent resolution logic, enhancing readability and maintainability. These changes improve the overall structure and usability of the QA request handling, facilitating easier updates and better code organization.
This commit is contained in:
@@ -32,43 +32,17 @@ type SessionService interface {
|
||||
// It emits an event when the title is generated
|
||||
// modelID: optional model ID to use for title generation (if empty, uses first available KnowledgeQA model)
|
||||
GenerateTitleAsync(ctx context.Context, session *types.Session, userQuery string, modelID string, eventBus *event.EventBus)
|
||||
// KnowledgeQA performs knowledge-based question answering
|
||||
// knowledgeBaseIDs: list of knowledge base IDs to search (supports multi-KB)
|
||||
// knowledgeIDs: list of specific knowledge (file) IDs to search
|
||||
// summaryModelID: optional summary model ID override (if empty, uses session/KB default)
|
||||
// webSearchEnabled: whether to enable web search to supplement knowledge base results
|
||||
// customAgent: optional custom agent for config override (multiTurnEnabled, historyTurns)
|
||||
// enableMemory: whether to enable memory feature for this request
|
||||
// Events are emitted through eventBus (references, answer chunks, completion)
|
||||
KnowledgeQA(ctx context.Context,
|
||||
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, imageDescription string, userMessageID string,
|
||||
) error
|
||||
// KnowledgeQA performs knowledge-based question answering.
|
||||
// Events are emitted through eventBus (references, answer chunks, completion).
|
||||
KnowledgeQA(ctx context.Context, req *types.QARequest, eventBus *event.EventBus) error
|
||||
// KnowledgeQAByEvent performs knowledge-based question answering by event
|
||||
KnowledgeQAByEvent(ctx context.Context, chatManage *types.ChatManage, eventList []types.EventType) error
|
||||
// SearchKnowledge performs knowledge-based search, without summarization
|
||||
// knowledgeBaseIDs: list of knowledge base IDs to search (supports multi-KB)
|
||||
// knowledgeIDs: list of specific knowledge (file) IDs to search
|
||||
SearchKnowledge(ctx context.Context, knowledgeBaseIDs []string, knowledgeIDs []string, query string) ([]*types.SearchResult, error)
|
||||
// AgentQA performs agent-based question answering with conversation history and streaming support
|
||||
// eventBus is optional - if nil, uses service's default EventBus
|
||||
// customAgent is optional - if provided, uses custom agent configuration instead of tenant defaults
|
||||
// summaryModelID is optional - if provided, overrides the model from customAgent config
|
||||
AgentQA(
|
||||
ctx context.Context,
|
||||
session *types.Session,
|
||||
query string,
|
||||
assistantMessageID string,
|
||||
summaryModelID string,
|
||||
eventBus *event.EventBus,
|
||||
customAgent *types.CustomAgent,
|
||||
knowledgeBaseIDs []string,
|
||||
knowledgeIDs []string,
|
||||
imageURLs []string, imageDescription string, userMessageID string,
|
||||
webSearchEnabled bool,
|
||||
) error
|
||||
// AgentQA performs agent-based question answering with conversation history and streaming support.
|
||||
AgentQA(ctx context.Context, req *types.QARequest, eventBus *event.EventBus) error
|
||||
// ClearContext clears the LLM context for a session
|
||||
ClearContext(ctx context.Context, sessionID string) error
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package types
|
||||
|
||||
// QARequest consolidates all parameters for KnowledgeQA and AgentQA service calls,
|
||||
// replacing the previous 14-parameter method signatures.
|
||||
// EventBus is passed separately to avoid circular dependency with the event package.
|
||||
type QARequest struct {
|
||||
Session *Session // The conversation session
|
||||
Query string // User query text
|
||||
AssistantMessageID string // Pre-created assistant message ID
|
||||
SummaryModelID string // Optional model override; empty = use agent/KB default
|
||||
CustomAgent *CustomAgent // Optional custom agent for config override
|
||||
KnowledgeBaseIDs []string // Knowledge base IDs to search (from request + @mentions)
|
||||
KnowledgeIDs []string // Specific knowledge (file) IDs to search
|
||||
ImageURLs []string // Image URLs for multimodal input
|
||||
ImageDescription string // VLM-generated image description (fallback for non-vision models)
|
||||
UserMessageID string // Created user message ID
|
||||
WebSearchEnabled bool // Whether web search is enabled for this request
|
||||
EnableMemory bool // Whether memory feature is enabled
|
||||
}
|
||||
Reference in New Issue
Block a user