diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-11 00:21:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-11 00:21:50 +0300 |
| commit | 2b2f4110da53a03742faff89cdec17c55e091a90 (patch) | |
| tree | b0c355f2470dbf984f373e0dcc45f12d00960a98 /internal/llm/openai.go | |
| parent | 1f3ae20a9830fd776f6ef3c11b4c198154b8205f (diff) | |
llm: return concrete client types from provider constructors
Follow the Go idiom "return concrete types, accept interfaces": the
provider constructors newOpenAI, newAnthropic, newOpenRouter, newOllama
and their *WithTimeout variants now return their concrete *Client value
types instead of the Client interface. The provider factories registered
in the registry still return Client, so NewFromConfig and the registry
keep working unchanged.
Updated comments to explain the reasoning, dropped the now-redundant
type assertions in tests, and switched the anthropic Streamer-capability
tests to assert via an explicit Client interface value.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/llm/openai.go')
| -rw-r--r-- | internal/llm/openai.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/internal/llm/openai.go b/internal/llm/openai.go index a119fe7..d475de0 100644 --- a/internal/llm/openai.go +++ b/internal/llm/openai.go @@ -110,11 +110,14 @@ func resolveOpenAITemperature(model string, configured *float64) *float64 { // 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, defaultTemp *float64) Client { +// Following the Go idiom "return concrete types, accept interfaces", this +// returns openAIClient directly so callers keep full type information; the +// provider registry wraps it back into a Client at registration time. +func newOpenAI(baseURL, model, apiKey string, defaultTemp *float64) openAIClient { return newOpenAIWithTimeout(baseURL, model, apiKey, defaultTemp, 0) } -func newOpenAIWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) Client { +func newOpenAIWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) openAIClient { if strings.TrimSpace(baseURL) == "" { baseURL = "https://api.openai.com/v1" } |
