From 7bbe7093da97f51cdde19a5abd580c290a815cd1 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 14:32:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=201.=E5=87=8F=E5=B0=91=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E8=BD=AE=E6=95=B0=202.=E5=AF=B9=E8=AF=9D=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E5=8A=A9=E6=89=8B=E5=9B=9E=E5=A4=8D=E9=99=8D=E5=99=AA?= =?UTF-8?q?=203.=E8=A7=92=E8=89=B2=E5=8C=B9=E9=85=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 2 +- config/config_env.yaml | 2 +- config/config_test.yaml | 2 +- internal/biz/router.go | 22 ++++++++++++++++++++-- internal/pkg/utils_ollama/client.go | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 2e6903f..85769d0 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -31,7 +31,7 @@ lsxd: sys: - session_len: 6 + session_len: 3 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/config/config_env.yaml b/config/config_env.yaml index b571f51..0e002e0 100644 --- a/config/config_env.yaml +++ b/config/config_env.yaml @@ -32,7 +32,7 @@ lsxd: sys: - session_len: 6 + session_len: 3 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/config/config_test.yaml b/config/config_test.yaml index 7355304..2e9e778 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -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 diff --git a/internal/biz/router.go b/internal/biz/router.go index 7d045f8..2d827dc 100644 --- a/internal/biz/router.go +++ b/internal/biz/router.go @@ -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 +} diff --git a/internal/pkg/utils_ollama/client.go b/internal/pkg/utils_ollama/client.go index fa88afa..febd8cd 100644 --- a/internal/pkg/utils_ollama/client.go +++ b/internal/pkg/utils_ollama/client.go @@ -53,6 +53,7 @@ func (c *Client) ToolSelect(ctx context.Context, messages []api.Message, tools [ res = resp return nil }) + if err != nil { return }