Skip to content

Commit

Permalink
fix parsing tool calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyng committed Jul 18, 2024
1 parent 70b1010 commit 43606d6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down

0 comments on commit 43606d6

Please sign in to comment.