@@ -90,12 +90,23 @@ func (s *ConversationService) CreateConversation(userID uint, req *request.Creat
|
|||||||
|
|
||||||
// 如果角色有开场白,创建开场白消息
|
// 如果角色有开场白,创建开场白消息
|
||||||
if character.FirstMes != "" {
|
if character.FirstMes != "" {
|
||||||
|
// 获取用户信息
|
||||||
|
var user app.AppUser
|
||||||
|
err = global.GVA_DB.Where("id = ?", userID).First(&user).Error
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Warn(fmt.Sprintf("获取用户信息失败: %v", err))
|
||||||
|
}
|
||||||
|
userName := user.Username
|
||||||
|
if userName == "" {
|
||||||
|
userName = user.NickName
|
||||||
|
}
|
||||||
|
|
||||||
// 应用输出阶段正则脚本处理开场白
|
// 应用输出阶段正则脚本处理开场白
|
||||||
processedFirstMes := character.FirstMes
|
processedFirstMes := character.FirstMes
|
||||||
var regexService RegexScriptService
|
var regexService RegexScriptService
|
||||||
outputScripts, err := regexService.GetScriptsForPlacement(userID, 1, &character.ID, nil)
|
outputScripts, err := regexService.GetScriptsForPlacement(userID, 1, &character.ID, nil)
|
||||||
if err == nil && len(outputScripts) > 0 {
|
if err == nil && len(outputScripts) > 0 {
|
||||||
processedFirstMes = regexService.ExecuteScripts(outputScripts, processedFirstMes, "", character.Name)
|
processedFirstMes = regexService.ExecuteScripts(outputScripts, processedFirstMes, userName, character.Name)
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("开场白应用正则脚本: 原始长度=%d, 处理后长度=%d", len(character.FirstMes), len(processedFirstMes)))
|
global.GVA_LOG.Info(fmt.Sprintf("开场白应用正则脚本: 原始长度=%d, 处理后长度=%d", len(character.FirstMes), len(processedFirstMes)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,6 +336,17 @@ func (s *ConversationService) SendMessage(userID, conversationID uint, req *requ
|
|||||||
return nil, errors.New("角色卡不存在")
|
return nil, errors.New("角色卡不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
var user app.AppUser
|
||||||
|
err = global.GVA_DB.Where("id = ?", userID).First(&user).Error
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Warn(fmt.Sprintf("获取用户信息失败: %v", err))
|
||||||
|
}
|
||||||
|
userName := user.Username
|
||||||
|
if userName == "" {
|
||||||
|
userName = user.NickName
|
||||||
|
}
|
||||||
|
|
||||||
// 应用输入阶段的正则脚本 (Placement 0)
|
// 应用输入阶段的正则脚本 (Placement 0)
|
||||||
processedContent := req.Content
|
processedContent := req.Content
|
||||||
var regexService RegexScriptService
|
var regexService RegexScriptService
|
||||||
@@ -335,7 +357,7 @@ func (s *ConversationService) SendMessage(userID, conversationID uint, req *requ
|
|||||||
} else {
|
} else {
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("找到 %d 个输入阶段正则脚本", len(inputScripts)))
|
global.GVA_LOG.Info(fmt.Sprintf("找到 %d 个输入阶段正则脚本", len(inputScripts)))
|
||||||
if len(inputScripts) > 0 {
|
if len(inputScripts) > 0 {
|
||||||
processedContent = regexService.ExecuteScripts(inputScripts, processedContent, "", character.Name)
|
processedContent = regexService.ExecuteScripts(inputScripts, processedContent, userName, character.Name)
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("应用了 %d 个输入阶段正则脚本,原文: %s, 处理后: %s", len(inputScripts), req.Content, processedContent))
|
global.GVA_LOG.Info(fmt.Sprintf("应用了 %d 个输入阶段正则脚本,原文: %s, 处理后: %s", len(inputScripts), req.Content, processedContent))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,7 +422,7 @@ func (s *ConversationService) SendMessage(userID, conversationID uint, req *requ
|
|||||||
displayContent := assistantMessage.Content
|
displayContent := assistantMessage.Content
|
||||||
displayScripts, err := regexService.GetScriptsForPlacement(userID, 3, &conversation.CharacterID, nil)
|
displayScripts, err := regexService.GetScriptsForPlacement(userID, 3, &conversation.CharacterID, nil)
|
||||||
if err == nil && len(displayScripts) > 0 {
|
if err == nil && len(displayScripts) > 0 {
|
||||||
displayContent = regexService.ExecuteScripts(displayScripts, displayContent, "", character.Name)
|
displayContent = regexService.ExecuteScripts(displayScripts, displayContent, userName, character.Name)
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("应用了 %d 个显示阶段正则脚本", len(displayScripts)))
|
global.GVA_LOG.Info(fmt.Sprintf("应用了 %d 个显示阶段正则脚本", len(displayScripts)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,8 +586,19 @@ func (s *ConversationService) callAIService(conversation app.Conversation, chara
|
|||||||
} else {
|
} else {
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("找到 %d 个输出阶段正则脚本", len(outputScripts)))
|
global.GVA_LOG.Info(fmt.Sprintf("找到 %d 个输出阶段正则脚本", len(outputScripts)))
|
||||||
if len(outputScripts) > 0 {
|
if len(outputScripts) > 0 {
|
||||||
|
// 获取用户信息
|
||||||
|
var user app.AppUser
|
||||||
|
err = global.GVA_DB.Where("id = ?", conversation.UserID).First(&user).Error
|
||||||
|
userName := ""
|
||||||
|
if err == nil {
|
||||||
|
userName = user.Username
|
||||||
|
if userName == "" {
|
||||||
|
userName = user.NickName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
originalResponse := aiResponse
|
originalResponse := aiResponse
|
||||||
aiResponse = regexService.ExecuteScripts(outputScripts, aiResponse, "", character.Name)
|
aiResponse = regexService.ExecuteScripts(outputScripts, aiResponse, userName, character.Name)
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("应用了 %d 个输出阶段正则脚本,原文: %s, 处理后: %s", len(outputScripts), originalResponse, aiResponse))
|
global.GVA_LOG.Info(fmt.Sprintf("应用了 %d 个输出阶段正则脚本,原文: %s, 处理后: %s", len(outputScripts), originalResponse, aiResponse))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -697,6 +730,17 @@ func (s *ConversationService) SendMessageStream(userID, conversationID uint, req
|
|||||||
return errors.New("角色卡不存在")
|
return errors.New("角色卡不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
var user app.AppUser
|
||||||
|
err = global.GVA_DB.Where("id = ?", userID).First(&user).Error
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Warn(fmt.Sprintf("[流式传输] 获取用户信息失败: %v", err))
|
||||||
|
}
|
||||||
|
userName := user.Username
|
||||||
|
if userName == "" {
|
||||||
|
userName = user.NickName
|
||||||
|
}
|
||||||
|
|
||||||
// 应用输入阶段的正则脚本 (Placement 0)
|
// 应用输入阶段的正则脚本 (Placement 0)
|
||||||
processedContent := req.Content
|
processedContent := req.Content
|
||||||
var regexService RegexScriptService
|
var regexService RegexScriptService
|
||||||
@@ -707,7 +751,7 @@ func (s *ConversationService) SendMessageStream(userID, conversationID uint, req
|
|||||||
} else {
|
} else {
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 找到 %d 个输入阶段正则脚本", len(inputScripts)))
|
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 找到 %d 个输入阶段正则脚本", len(inputScripts)))
|
||||||
if len(inputScripts) > 0 {
|
if len(inputScripts) > 0 {
|
||||||
processedContent = regexService.ExecuteScripts(inputScripts, processedContent, "", character.Name)
|
processedContent = regexService.ExecuteScripts(inputScripts, processedContent, userName, character.Name)
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 应用了 %d 个输入阶段正则脚本", len(inputScripts)))
|
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 应用了 %d 个输入阶段正则脚本", len(inputScripts)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -862,7 +906,7 @@ func (s *ConversationService) SendMessageStream(userID, conversationID uint, req
|
|||||||
} else {
|
} else {
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 找到 %d 个输出阶段正则脚本", len(outputScripts)))
|
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 找到 %d 个输出阶段正则脚本", len(outputScripts)))
|
||||||
if len(outputScripts) > 0 {
|
if len(outputScripts) > 0 {
|
||||||
fullContent = regexService.ExecuteScripts(outputScripts, fullContent, "", character.Name)
|
fullContent = regexService.ExecuteScripts(outputScripts, fullContent, userName, character.Name)
|
||||||
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 应用了 %d 个输出阶段正则脚本", len(outputScripts)))
|
global.GVA_LOG.Info(fmt.Sprintf("[流式传输] 应用了 %d 个输出阶段正则脚本", len(outputScripts)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user