Skip to content

Commit

Permalink
feat: jb can set the locale for chat (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: mibody2 <mibody2>
  • Loading branch information
mibody2 authored May 19, 2024
1 parent ed40f68 commit 7992cbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 12,6 @@
"chat_api_project": "",
"chat_max_tokens": 4096,
"chat_model_default": "gpt-4o",
"chat_model_map": {}
"chat_model_map": {},
"chat_locale": "zh_CN"
}
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,7 @@ type config struct {
ChatMaxTokens int `json:"chat_max_tokens"`
ChatModelDefault string `json:"chat_model_default"`
ChatModelMap map[string]string `json:"chat_model_map"`
ChatLocale string `json:"chat_locale"`
}

func readConfig() *config {
Expand Down Expand Up @@ -171,6 172,19 @@ func (s *ProxyService) completions(c *gin.Context) {
model = s.cfg.ChatModelDefault
}
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_threshold")
body, _ = sjson.DeleteBytes(body, "intent_content")
Expand Down

0 comments on commit 7992cbe

Please sign in to comment.