diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-02 14:34:46 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-02 14:34:46 +0200 |
| commit | 986456be623ba1974fdf06bfdfcaeffd8cd13bb7 (patch) | |
| tree | ada0248bc5dfc32a7355dc088742089262a270fd /internal/llm/openai.go | |
| parent | 3e3d1cb988b457a55425a7334f8f5a91cc939666 (diff) | |
llm: extract shared doJSON and logStart helpers (task 409)
Diffstat (limited to 'internal/llm/openai.go')
| -rw-r--r-- | internal/llm/openai.go | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/internal/llm/openai.go b/internal/llm/openai.go index 5c1e525..3d2bf94 100644 --- a/internal/llm/openai.go +++ b/internal/llm/openai.go @@ -3,7 +3,6 @@ package llm import ( "bufio" - "bytes" "context" "encoding/json" "errors" @@ -237,11 +236,7 @@ func (c openAIClient) logf(format string, args ...any) { logging.Logf("llm/opena // helpers extracted to keep methods small func (c openAIClient) logStart(stream bool, o Options, messages []Message) { - logMessages := make([]struct{ Role, Content string }, len(messages)) - for i, m := range messages { - logMessages[i] = struct{ Role, Content string }{m.Role, m.Content} - } - c.chatLogger.LogStart(stream, o.Model, o.Temperature, o.MaxTokens, o.Stop, logMessages) + logStartMessages(c.chatLogger, stream, o, messages) } func buildOAChatRequest(o Options, messages []Message, defaultTemp *float64, stream bool, logPrefix string) oaChatRequest { @@ -286,28 +281,11 @@ func requiresMaxCompletionTokens(model string) bool { } func (c openAIClient) doJSON(ctx context.Context, url string, body []byte, headers map[string]string) (*http.Response, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body)) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/json") - for k, v := range headers { - req.Header.Set(k, v) - } - return c.httpClient.Do(req) + return doJSONRequest(ctx, c.httpClient, url, body, headers, "") } func (c openAIClient) doJSONWithAccept(ctx context.Context, url string, body []byte, headers map[string]string, accept string) (*http.Response, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body)) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", accept) - for k, v := range headers { - req.Header.Set(k, v) - } - return c.httpClient.Do(req) + return doJSONRequest(ctx, c.httpClient, url, body, headers, accept) } func handleOpenAINon2xx(resp *http.Response, start time.Time, logPrefix, provider string) error { |
