From 9ef70da47bfd129ab557072c3ab3a1965c31350f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E5=A4=95=E6=98=AF=E4=BD=95=E5=B9=B4?= Date: Wed, 25 Sep 2024 15:10:50 +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?= =?UTF-8?q?=20(#57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: liyuzhe --- 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