summaryrefslogtreecommitdiff
path: root/internal/llm/openai.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-02 13:33:08 +0200
committerPaul Buetow <paul@buetow.org>2026-03-02 13:33:08 +0200
commit3bd295d60ecbb30852e8bcf672b1befd93eb9bff (patch)
tree2a530a83cb766a990a31d98d16328aaf634c1eeb /internal/llm/openai.go
parent10406467650942b780e5de462d5103431c5a951e (diff)
llm: add provider registry and self-registration factories (task 410)
Diffstat (limited to 'internal/llm/openai.go')
-rw-r--r--internal/llm/openai.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/llm/openai.go b/internal/llm/openai.go
index 6bc3a7c..5c1e525 100644
--- a/internal/llm/openai.go
+++ b/internal/llm/openai.go
@@ -73,6 +73,39 @@ type oaStreamChunk struct {
} `json:"error,omitempty"`
}
+func init() {
+ RegisterProvider("openai", openAIProviderFactory)
+}
+
+func openAIProviderFactory(cfg Config, keys ProviderKeys) (Client, error) {
+ if strings.TrimSpace(keys.OpenAIAPIKey) == "" {
+ return nil, errors.New("missing OPENAI_API_KEY for provider openai")
+ }
+ return newOpenAIWithTimeout(
+ cfg.OpenAIBaseURL,
+ cfg.OpenAIModel,
+ keys.OpenAIAPIKey,
+ resolveOpenAITemperature(cfg.OpenAIModel, cfg.OpenAITemperature),
+ cfg.RequestTimeout,
+ ), nil
+}
+
+func resolveOpenAITemperature(model string, configured *float64) *float64 {
+ isGPT5 := strings.HasPrefix(strings.ToLower(strings.TrimSpace(model)), "gpt-5")
+ if isGPT5 {
+ if configured == nil || *configured == 0.2 {
+ v := 1.0
+ return &v
+ }
+ return configured
+ }
+ if configured != nil {
+ return configured
+ }
+ v := 0.2
+ return &v
+}
+
// 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.