feat: jb can set the locale for chat

This commit is contained in:
mibody2 2024-05-19 22:22:03 +08:00
parent ed40f68e99
commit 8f4456c4ef
2 changed files with 16 additions and 1 deletions

View File

@ -12,5 +12,6 @@
"chat_api_project": "", "chat_api_project": "",
"chat_max_tokens": 4096, "chat_max_tokens": 4096,
"chat_model_default": "gpt-4o", "chat_model_default": "gpt-4o",
"chat_model_map": {} "chat_model_map": {},
"chat_locale": "zh_CN"
} }

14
main.go
View File

@ -37,6 +37,7 @@ type config struct {
ChatMaxTokens int `json:"chat_max_tokens"` ChatMaxTokens int `json:"chat_max_tokens"`
ChatModelDefault string `json:"chat_model_default"` ChatModelDefault string `json:"chat_model_default"`
ChatModelMap map[string]string `json:"chat_model_map"` ChatModelMap map[string]string `json:"chat_model_map"`
ChatLocale string `json:"chat_locale"`
} }
func readConfig() *config { func readConfig() *config {
@ -171,6 +172,19 @@ func (s *ProxyService) completions(c *gin.Context) {
model = s.cfg.ChatModelDefault model = s.cfg.ChatModelDefault
} }
body, _ = sjson.SetBytes(body, "model", model) body, _ = sjson.SetBytes(body, "model", model)
if !gjson.GetBytes(body, "function_call").Exists() {
messages := gjson.GetBytes(body, "messages").Array()
lastIndex := len(messages) - 1
if !strings.Contains(messages[lastIndex].Get("content").String(), "Respond in the following locale") {
locale := s.cfg.ChatLocale
if locale == "" {
locale = "zh_CN"
}
body, _ = sjson.SetBytes(body, "messages."+strconv.Itoa(lastIndex)+".content", messages[lastIndex].Get("content").String()+"Respond in the following locale: "+locale+".")
}
}
body, _ = sjson.DeleteBytes(body, "intent") body, _ = sjson.DeleteBytes(body, "intent")
body, _ = sjson.DeleteBytes(body, "intent_threshold") body, _ = sjson.DeleteBytes(body, "intent_threshold")
body, _ = sjson.DeleteBytes(body, "intent_content") body, _ = sjson.DeleteBytes(body, "intent_content")