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/openrouter.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/openrouter.go')
| -rw-r--r-- | internal/llm/openrouter.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/internal/llm/openrouter.go b/internal/llm/openrouter.go index aa8a4d4..d728275 100644 --- a/internal/llm/openrouter.go +++ b/internal/llm/openrouter.go @@ -40,11 +40,15 @@ func openRouterProviderFactory(cfg Config, keys ProviderKeys) (Client, error) { ), nil } -func newOpenRouter(baseURL, model, apiKey string, defaultTemp *float64) Client { +// newOpenRouter constructs an OpenRouter client using explicit configuration +// values. Following the Go idiom "return concrete types, accept interfaces", +// this returns openRouterClient directly; the provider registry wraps it back +// into a Client at registration time. +func newOpenRouter(baseURL, model, apiKey string, defaultTemp *float64) openRouterClient { return newOpenRouterWithTimeout(baseURL, model, apiKey, defaultTemp, 0) } -func newOpenRouterWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) Client { +func newOpenRouterWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) openRouterClient { if strings.TrimSpace(baseURL) == "" { baseURL = "https://openrouter.ai/api/v1" } |
