当message中的tool_calls字段为空数组时移除掉这个属性,防止deepseek报错。 (#57)

Co-authored-by: liyuzhe <banyebushui@>
This commit is contained in:
今夕是何年 2024-09-25 15:10:50 +08:00 committed by GitHub
parent aef14559a1
commit 9ef70da47b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -398,6 +398,12 @@ func (s *ProxyService) completions(c *gin.Context) {
if !gjson.GetBytes(body, "function_call").Exists() { if !gjson.GetBytes(body, "function_call").Exists() {
messages := gjson.GetBytes(body, "messages").Array() messages := gjson.GetBytes(body, "messages").Array()
for i, msg := range messages {
toolCalls := msg.Get("tool_calls").Array()
if len(toolCalls) == 0 {
body, _ = sjson.DeleteBytes(body, fmt.Sprintf("messages.%d.tool_calls", i))
}
}
lastIndex := len(messages) - 1 lastIndex := len(messages) - 1
if !strings.Contains(messages[lastIndex].Get("content").String(), "Respond in the following locale") { if !strings.Contains(messages[lastIndex].Get("content").String(), "Respond in the following locale") {
locale := s.cfg.ChatLocale locale := s.cfg.ChatLocale