From 7807741faf118f0ebce37fd0bca7f8b4390fc116 Mon Sep 17 00:00:00 2001 From: pennbay Date: Fri, 6 Dec 2024 08:15:24 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Enhance=20locale=20response?= =?UTF-8?q?=20handling=20in=20chat=20completions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 用户定义了 CHAT_LOCALE 时,才附加Response in xxx - 如果用户没有定义CHAT_LOCALE,则无需附加此句。实现中文问中文答,英文问英文答的效果。 --- internal/controller/copilot/chat_completions.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/controller/copilot/chat_completions.go b/internal/controller/copilot/chat_completions.go index bfe0d70..8ea252f 100644 --- a/internal/controller/copilot/chat_completions.go +++ b/internal/controller/copilot/chat_completions.go @@ -39,8 +39,9 @@ func chatCompletions(c *gin.Context) { } } lastIndex := len(messages) - 1 - if !strings.Contains(messages[lastIndex].Get("content").String(), "Respond in the following locale") { - body, _ = sjson.SetBytes(body, "messages."+strconv.Itoa(lastIndex)+".content", messages[lastIndex].Get("content").String()+"Respond in the following locale: "+os.Getenv("CHAT_LOCALE")+".") + chatLocale := os.Getenv("CHAT_LOCALE") + if chatLocale != "" && !strings.Contains(messages[lastIndex].Get("content").String(), "Respond in the following locale") { + body, _ = sjson.SetBytes(body, "messages."+strconv.Itoa(lastIndex)+".content", messages[lastIndex].Get("content").String()+"Respond in the following locale: "+chatLocale+".") } } -- Gitee