parent
7be0c5ecd2
commit
075342606f
|
|
@ -11,6 +11,7 @@
|
||||||
"chat_api_key": "sk-xxx",
|
"chat_api_key": "sk-xxx",
|
||||||
"chat_api_organization": "",
|
"chat_api_organization": "",
|
||||||
"chat_api_project": "",
|
"chat_api_project": "",
|
||||||
|
"chat_max_tokens": 4096,
|
||||||
"chat_model_default": "gpt-4o",
|
"chat_model_default": "gpt-4o",
|
||||||
"chat_model_map": {}
|
"chat_model_map": {}
|
||||||
}
|
}
|
||||||
5
main.go
5
main.go
|
|
@ -36,6 +36,7 @@ type config struct {
|
||||||
ChatApiKey string `json:"chat_api_key"`
|
ChatApiKey string `json:"chat_api_key"`
|
||||||
ChatApiOrganization string `json:"chat_api_organization"`
|
ChatApiOrganization string `json:"chat_api_organization"`
|
||||||
ChatApiProject string `json:"chat_api_project"`
|
ChatApiProject string `json:"chat_api_project"`
|
||||||
|
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"`
|
||||||
}
|
}
|
||||||
|
|
@ -183,6 +184,10 @@ func (s *ProxyService) completions(c *gin.Context) {
|
||||||
body, _ = sjson.DeleteBytes(body, "intent_threshold")
|
body, _ = sjson.DeleteBytes(body, "intent_threshold")
|
||||||
body, _ = sjson.DeleteBytes(body, "intent_content")
|
body, _ = sjson.DeleteBytes(body, "intent_content")
|
||||||
|
|
||||||
|
if int(gjson.GetBytes(body, "max_tokens").Int()) > s.cfg.ChatMaxTokens {
|
||||||
|
body, _ = sjson.SetBytes(body, "max_tokens", s.cfg.ChatMaxTokens)
|
||||||
|
}
|
||||||
|
|
||||||
proxyUrl := s.cfg.ChatApiBase + "/chat/completions"
|
proxyUrl := s.cfg.ChatApiBase + "/chat/completions"
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, proxyUrl, io.NopCloser(bytes.NewBuffer(body)))
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, proxyUrl, io.NopCloser(bytes.NewBuffer(body)))
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue