@@ -72,13 +72,15 @@ func (s *ConversationService) CreateConversation(userID uint, req *request.Creat
|
||||
|
||||
// 创建对话
|
||||
conversation := app.Conversation{
|
||||
UserID: userID,
|
||||
CharacterID: req.CharacterID,
|
||||
Title: title,
|
||||
PresetID: req.PresetID,
|
||||
AIProvider: aiProvider,
|
||||
Model: model,
|
||||
Settings: datatypes.JSON("{}"),
|
||||
UserID: userID,
|
||||
CharacterID: req.CharacterID,
|
||||
Title: title,
|
||||
PresetID: req.PresetID,
|
||||
WorldbookID: req.WorldbookID,
|
||||
WorldbookEnabled: req.WorldbookEnabled,
|
||||
AIProvider: aiProvider,
|
||||
Model: model,
|
||||
Settings: datatypes.JSON("{}"),
|
||||
}
|
||||
|
||||
err = global.GVA_DB.Create(&conversation).Error
|
||||
@@ -188,7 +190,7 @@ func (s *ConversationService) GetConversationByID(userID, conversationID uint) (
|
||||
}
|
||||
|
||||
// UpdateConversationSettings 更新对话设置
|
||||
func (s *ConversationService) UpdateConversationSettings(userID, conversationID uint, settings map[string]interface{}) error {
|
||||
func (s *ConversationService) UpdateConversationSettings(userID, conversationID uint, req *request.UpdateConversationSettingsRequest) error {
|
||||
var conversation app.Conversation
|
||||
err := global.GVA_DB.Where("id = ? AND user_id = ?", conversationID, userID).First(&conversation).Error
|
||||
if err != nil {
|
||||
@@ -198,13 +200,32 @@ func (s *ConversationService) UpdateConversationSettings(userID, conversationID
|
||||
return err
|
||||
}
|
||||
|
||||
// 序列化设置
|
||||
settingsJSON, err := json.Marshal(settings)
|
||||
if err != nil {
|
||||
return err
|
||||
updates := make(map[string]interface{})
|
||||
|
||||
// 更新设置
|
||||
if req.Settings != nil {
|
||||
settingsJSON, err := json.Marshal(req.Settings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updates["settings"] = datatypes.JSON(settingsJSON)
|
||||
}
|
||||
|
||||
return global.GVA_DB.Model(&conversation).Update("settings", datatypes.JSON(settingsJSON)).Error
|
||||
// 更新世界书ID
|
||||
if req.WorldbookID != nil {
|
||||
updates["worldbook_id"] = req.WorldbookID
|
||||
}
|
||||
|
||||
// 更新世界书启用状态
|
||||
if req.WorldbookEnabled != nil {
|
||||
updates["worldbook_enabled"] = *req.WorldbookEnabled
|
||||
}
|
||||
|
||||
if len(updates) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return global.GVA_DB.Model(&conversation).Updates(updates).Error
|
||||
}
|
||||
|
||||
// DeleteConversation 删除对话
|
||||
@@ -431,6 +452,30 @@ func (s *ConversationService) callAIService(conversation app.Conversation, chara
|
||||
global.GVA_LOG.Info("已追加预设的系统提示词")
|
||||
}
|
||||
|
||||
// 集成世界书触发引擎
|
||||
if conversation.WorldbookEnabled && conversation.WorldbookID != nil {
|
||||
global.GVA_LOG.Info(fmt.Sprintf("世界书已启用,ID: %d", *conversation.WorldbookID))
|
||||
|
||||
// 提取消息内容用于扫描
|
||||
var messageContents []string
|
||||
for _, msg := range messages {
|
||||
messageContents = append(messageContents, msg.Content)
|
||||
}
|
||||
|
||||
// 使用世界书引擎扫描并触发条目
|
||||
engine := &WorldbookEngine{}
|
||||
triggered, err := engine.ScanAndTrigger(*conversation.WorldbookID, messageContents)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Warn(fmt.Sprintf("世界书触发失败: %v", err))
|
||||
} else if len(triggered) > 0 {
|
||||
global.GVA_LOG.Info(fmt.Sprintf("触发了 %d 个世界书条目", len(triggered)))
|
||||
// 将触发的世界书内容注入到系统提示词
|
||||
systemPrompt = engine.BuildPromptWithWorldbook(systemPrompt, triggered)
|
||||
} else {
|
||||
global.GVA_LOG.Info("没有触发任何世界书条目")
|
||||
}
|
||||
}
|
||||
|
||||
// 构建消息列表
|
||||
apiMessages := s.buildAPIMessages(messages, systemPrompt)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user