up
This commit is contained in:
@@ -494,6 +494,22 @@ func (LLMToolRouterRecord) TableName() string {
|
||||
return "llm_tool_router"
|
||||
}
|
||||
|
||||
// LLMTopicConfigRecord 保存话题选择的配置
|
||||
type LLMTopicConfigRecord struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement"`
|
||||
Enabled bool `gorm:"column:enabled;not null;index"` // 是否启用话题选择
|
||||
OpenAIName string `gorm:"column:openai_name;size:64;not null"` // 使用的 LLM 提供商名称(关联 llm_providers.name)
|
||||
Timeout int `gorm:"column:timeout;not null;default:30"` // 话题判定超时时间(秒)
|
||||
MaxTokens int `gorm:"column:max_tokens;not null;default:512"` // 话题判定最大 token 数
|
||||
SystemPrompt string `gorm:"column:system_prompt;type:text;not null"` // 系统提示词
|
||||
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime;index"`
|
||||
}
|
||||
|
||||
func (LLMTopicConfigRecord) TableName() string {
|
||||
return "llm_topic_config"
|
||||
}
|
||||
|
||||
// LLMPrimaryConfigRecord 保存主 AI 回复的配置
|
||||
type LLMPrimaryConfigRecord struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement"`
|
||||
@@ -666,6 +682,7 @@ func (s *Store) migrate() error {
|
||||
{label: "llm_message_queue", model: &LLMMessageQueueRecord{}},
|
||||
{label: "llm_providers", model: &LLMProviderRecord{}},
|
||||
{label: "llm_tool_router", model: &LLMToolRouterRecord{}},
|
||||
{label: "llm_topic_config", model: &LLMTopicConfigRecord{}},
|
||||
{label: "llm_primary_config", model: &LLMPrimaryConfigRecord{}},
|
||||
{label: "nodeinfo", model: &NodeInfoRecord{}},
|
||||
{label: "map_report", model: &MapReportRecord{}},
|
||||
@@ -713,6 +730,9 @@ func (s *Store) migrate() error {
|
||||
if err := txStore.EnsureDefaultLLMToolRouter(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := txStore.EnsureDefaultLLMTopicConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := txStore.EnsureDefaultLLMPrimaryConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -139,6 +139,59 @@ func (s *Store) EnsureDefaultLLMToolRouter() error {
|
||||
return s.CreateLLMToolRouter(defaultConfig)
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// LLM Topic Config (llm_topic_config) - 话题选择配置
|
||||
// ============================================
|
||||
|
||||
// GetLLMTopicConfig 获取当前激活的话题选择配置
|
||||
func (s *Store) GetLLMTopicConfig() (*LLMTopicConfigRecord, error) {
|
||||
var record LLMTopicConfigRecord
|
||||
// 默认取第一条记录(ID 最小的),因为通常只需要一个配置
|
||||
if err := s.db.Order("id ASC").First(&record).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("get llm topic config: %w", err)
|
||||
}
|
||||
return &record, nil
|
||||
}
|
||||
|
||||
// CreateLLMTopicConfig 创建话题选择配置
|
||||
func (s *Store) CreateLLMTopicConfig(record *LLMTopicConfigRecord) error {
|
||||
if err := s.db.Create(record).Error; err != nil {
|
||||
return fmt.Errorf("create llm topic config: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateLLMTopicConfig 更新话题选择配置
|
||||
func (s *Store) UpdateLLMTopicConfig(id uint64, updates map[string]any) error {
|
||||
if err := s.db.Model(&LLMTopicConfigRecord{}).Where("id = ?", id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("update llm topic config %d: %w", id, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureDefaultLLMTopicConfig 确保存在默认话题选择配置
|
||||
func (s *Store) EnsureDefaultLLMTopicConfig() error {
|
||||
_, err := s.GetLLMTopicConfig()
|
||||
if err == nil {
|
||||
return nil // 已存在
|
||||
}
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
// 创建默认配置(默认未启用)
|
||||
defaultConfig := &LLMTopicConfigRecord{
|
||||
Enabled: false,
|
||||
OpenAIName: "",
|
||||
Timeout: 30,
|
||||
MaxTokens: 512,
|
||||
SystemPrompt: "你是一个话题过滤器,判断用户最新消息是否属于应当回复的话题范围。\n如果应当回复,请输出 REPLY;如果不应当回复,请输出 IGNORE。\n只输出 REPLY 或 IGNORE,不要输出任何其他内容。",
|
||||
}
|
||||
return s.CreateLLMTopicConfig(defaultConfig)
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// LLM Primary Config (llm_primary_config) - 主 AI 回复配置
|
||||
// ============================================
|
||||
|
||||
Reference in New Issue
Block a user