From 43606d6d6a0d5e4105692d6d1233cfaa96a562b0 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Thu, 18 Jul 2024 12:07:59 -0700 Subject: [PATCH] fix parsing tool calls --- server/model.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/model.go b/server/model.go index 65231ab1..a084dd8c 100644 --- a/server/model.go +++ b/server/model.go @@ -348,7 +348,7 @@ func (m *Model) parseToolCalls(s string) ([]api.ToolCall, bool) { for offset := 0; offset < len(s); { var obj map[string]any decoder := json.NewDecoder(strings.NewReader(s[offset:])) - if err := decoder.Decode(&obj); errors.Is(err, io.EOF) { + if err := decoder.Decode(&obj); errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) { break } else if syntax := &(json.SyntaxError{}); errors.As(err, &syntax) { // skip over any syntax errors @@ -357,6 +357,7 @@ func (m *Model) parseToolCalls(s string) ([]api.ToolCall, bool) { // skip over any unmarshalable types offset += int(unmarshalType.Offset) } else if err != nil { + slog.Error("parseToolCalls", "error", err) return nil, false } else { offset += int(decoder.InputOffset())