diff options
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 { |
