Use json v2

This commit is contained in:
dwrz
2026-10-11 00:55:57 +00:00
parent 81b981c07f
commit 75040646e3
5 changed files with 23 additions and 24 deletions
+4 -4
View File
@@ -4,7 +4,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/json"
"encoding/json/v2"
"fmt"
"io"
"log/slog"
@@ -83,7 +83,7 @@ func (c *Client) completions(
ThinkingBudgetTokens: p.ThinkingBudgetTokens,
ChatTemplateKWARGS: kwargs,
ParallelToolCalls: new(true),
})
}, json.FormatNilSliceAsNull(true))
if err != nil {
return nil, fmt.Errorf(
"completions: marshal request body: %w", err,
@@ -152,7 +152,7 @@ func (c *Client) completions(
}
var cr = &ChatResponse{}
if err := json.NewDecoder(res.Body).Decode(cr); err != nil {
if err := json.UnmarshalRead(res.Body, cr); err != nil {
return nil, fmt.Errorf("completions: decode response: %w", err)
}
if len(cr.Choices) == 0 {
@@ -283,7 +283,7 @@ func (c *Client) CompletionsStream(
StreamOptions: &StreamOptions{IncludeUsage: true},
ThinkingBudgetTokens: p.ThinkingBudgetTokens,
Tools: p.Tools,
})
}, json.FormatNilSliceAsNull(true))
if err != nil {
cancel()
return nil, fmt.Errorf(