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 }