fix: 1.减少上下文轮数 2.对话历史助手回复降噪 3.角色匹配错误修复

This commit is contained in:
fuzhongyun 2026-01-07 14:32:36 +08:00
parent 4452fb1568
commit 7bbe7093da
5 changed files with 24 additions and 5 deletions

View File

@ -31,7 +31,7 @@ lsxd:
sys:
session_len: 6
session_len: 3
channel_pool_len: 100
channel_pool_size: 32
llm_pool_len: 5

View File

@ -32,7 +32,7 @@ lsxd:
sys:
session_len: 6
session_len: 3
channel_pool_len: 100
channel_pool_size: 32
llm_pool_len: 5

View File

@ -32,7 +32,7 @@ lsxd:
check_token_url: "https://api.user.1688sup.com/v1/user/welcome"
sys:
session_len: 6
session_len: 3
channel_pool_len: 100
channel_pool_size: 32
llm_pool_len: 5

View File

@ -174,14 +174,15 @@ func (r *AiRouterBiz) buildChatHistory(requireData *entitys.RequireData) entitys
// 用户消息
messages = append(messages, entitys.HisMessage{
Role: constants.RoleUser, // 用户角色
Content: h.Ans, // 用户输入内容
Content: h.Ques, // 用户输入内容
Timestamp: h.CreateAt.Format(time.DateTime),
})
// 助手消息
ansStr := r.ansNoiseReduction(h.Ans) // 助手回复降噪
messages = append(messages, entitys.HisMessage{
Role: constants.RoleAssistant, // 助手角色
Content: h.Ques, // 助手回复内容
Content: ansStr, // 助手回复内容
Timestamp: h.CreateAt.Format(time.DateTime),
})
}
@ -196,3 +197,20 @@ func (r *AiRouterBiz) buildChatHistory(requireData *entitys.RequireData) entitys
},
}
}
// ansNoiseReduction 助手回复降噪
func (r *AiRouterBiz) ansNoiseReduction(ansJson string) string {
// 使用anw统一类型解析
ansStruct := make([]*entitys.Response, 0)
err := json.Unmarshal([]byte(ansJson), &ansStruct)
if err != nil {
log.Errorf("解析助手回复失败: %s", err.Error())
return ansJson
}
var ansStr string
for _, item := range ansStruct {
ansStr += item.Content
}
return ansStr
}

View File

@ -53,6 +53,7 @@ func (c *Client) ToolSelect(ctx context.Context, messages []api.Message, tools [
res = resp
return nil
})
if err != nil {
return
}