Skip to content

Commit

Permalink
当message中的tool_calls字段为空数组时移除掉这个属性,防止deepseek报错。 (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: liyuzhe <banyebushui@>
  • Loading branch information
JustLookAtNow authored Sep 25, 2024
1 parent aef1455 commit 9ef70da
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ef70da

Please sign in to comment.