From a43dc62cbd5d217cc240bfea25e4fcc788170fbc Mon Sep 17 00:00:00 2001 From: liyuzhe Date: Fri, 13 Sep 2024 21:49:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93message=E4=B8=AD=E7=9A=84tool=5Fcalls?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=BA=E7=A9=BA=E6=95=B0=E7=BB=84=E6=97=B6?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=8E=89=E8=BF=99=E4=B8=AA=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2deepseek=E6=8A=A5=E9=94=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index 5d60def..8209e67 100644 --- a/main.go +++ b/main.go @@ -398,6 +398,12 @@ func (s *ProxyService) completions(c *gin.Context) { if !gjson.GetBytes(body, "function_call").Exists() { 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 if !strings.Contains(messages[lastIndex].Get("content").String(), "Respond in the following locale") { locale := s.cfg.ChatLocale