refactor: Enhance chat message handling and session management

- Updated chat message sending logic to conditionally validate knowledge base IDs based on agent mode status.
- Improved endpoint selection for chat requests, allowing for dynamic routing between agent and knowledge chat.
- Introduced a new method to select the appropriate chat model ID, prioritizing remote models for enhanced flexibility.
- Changed JSON column types for agent and context configurations in session and tenant types to jsonb for better performance.
This commit is contained in:
wizardchen
2025-11-07 01:37:37 +08:00
parent 288dfbd19e
commit 655df49d7d
5 changed files with 98 additions and 13 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ type Message struct {
// Agent execution steps (only for assistant messages generated by agent)
// This contains the detailed reasoning process and tool calls made by the agent
// Stored for user history display, but NOT included in LLM context to avoid redundancy
AgentSteps AgentSteps `json:"agent_steps,omitempty" gorm:"type:json,column:agent_steps"`
AgentSteps AgentSteps `json:"agent_steps,omitempty" gorm:"type:jsonb,column:agent_steps"`
// Whether message generation is complete
IsCompleted bool `json:"is_completed"`
// Message creation timestamp
+2 -2
View File
@@ -93,8 +93,8 @@ type Session struct {
RerankThreshold float64 `json:"rerank_threshold"` // 排序阈值
SummaryModelID string `json:"summary_model_id"` // 总结模型ID
SummaryParameters *SummaryConfig `json:"summary_parameters" gorm:"type:json"` // 总结模型参数
AgentConfig *SessionAgentConfig `json:"agent_config" gorm:"type:json"` // Agent 配置(会话级别,仅存储enabled和knowledge_bases)
ContextConfig *ContextConfig `json:"context_config" gorm:"type:json"` // 上下文管理配置(可选)
AgentConfig *SessionAgentConfig `json:"agent_config" gorm:"type:jsonb"` // Agent 配置(会话级别,仅存储enabled和knowledge_bases)
ContextConfig *ContextConfig `json:"context_config" gorm:"type:jsonb"` // 上下文管理配置(可选)
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
+2 -2
View File
@@ -29,9 +29,9 @@ type Tenant struct {
// Storage used (Bytes)
StorageUsed int64 `yaml:"storage_used" json:"storage_used" gorm:"default:0"`
// Global Agent configuration for this tenant (default for all sessions)
AgentConfig *AgentConfig `yaml:"agent_config" json:"agent_config" gorm:"type:json"`
AgentConfig *AgentConfig `yaml:"agent_config" json:"agent_config" gorm:"type:jsonb"`
// Global Context configuration for this tenant (default for all sessions)
ContextConfig *ContextConfig `yaml:"context_config" json:"context_config" gorm:"type:json"`
ContextConfig *ContextConfig `yaml:"context_config" json:"context_config" gorm:"type:jsonb"`
// Creation time
CreatedAt time.Time `yaml:"created_at" json:"created_at"`
// Last updated time