diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-17 23:06:37 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-17 23:06:37 +0300 |
| commit | 041d1f140436c6fdd223844b04c6592c84951878 (patch) | |
| tree | e44df5d5691408216a26d472f7e96278095319d2 /internal/llm/openai.go | |
| parent | d72f95ae4e6cd4e7a0beca2b9764511c10de8655 (diff) | |
refactor(ordering): place constructors immediately after type definitions as first functions
Diffstat (limited to 'internal/llm/openai.go')
| -rw-r--r-- | internal/llm/openai.go | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/internal/llm/openai.go b/internal/llm/openai.go index ed5629e..8dc2907 100644 --- a/internal/llm/openai.go +++ b/internal/llm/openai.go @@ -72,6 +72,25 @@ type oaStreamChunk struct { } `json:"error,omitempty"` } +// Constructor (kept among the first functions by convention) +// newOpenAI constructs an OpenAI client using explicit configuration values. +// The apiKey may be empty; calls will fail until a valid key is supplied. +func newOpenAI(baseURL, model, apiKey string) Client { + if strings.TrimSpace(baseURL) == "" { + baseURL = "https://api.openai.com/v1" + } + if strings.TrimSpace(model) == "" { + model = "gpt-4.1" + } + return openAIClient{ + httpClient: &http.Client{Timeout: 30 * time.Second}, + apiKey: apiKey, + baseURL: baseURL, + defaultModel: model, + chatLogger: logging.NewChatLogger("openai"), + } +} + func (c openAIClient) Chat(ctx context.Context, messages []Message, opts ...RequestOption) (string, error) { if c.apiKey == "" { return nilStringErr("missing OpenAI API key") @@ -277,21 +296,3 @@ func (c openAIClient) ChatStream(ctx context.Context, messages []Message, onDelt // Private helpers func (c openAIClient) logf(format string, args ...any) { logging.Logf("llm/openai ", format, args...) } - -// newOpenAI constructs an OpenAI client using explicit configuration values. -// The apiKey may be empty; calls will fail until a valid key is supplied. -func newOpenAI(baseURL, model, apiKey string) Client { - if strings.TrimSpace(baseURL) == "" { - baseURL = "https://api.openai.com/v1" - } - if strings.TrimSpace(model) == "" { - model = "gpt-4.1" - } - return openAIClient{ - httpClient: &http.Client{Timeout: 30 * time.Second}, - apiKey: apiKey, - baseURL: baseURL, - defaultModel: model, - chatLogger: logging.NewChatLogger("openai"), - } -} |
