summaryrefslogtreecommitdiff
path: root/internal/llm/provider.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-10-02 08:41:45 +0300
committerPaul Buetow <paul@buetow.org>2025-10-02 08:41:45 +0300
commite36a5446bc62842ae3b3e165f66fecb7285a8c6a (patch)
treed3f9f7a66d8b4e5fdb13903722580a8f90eae5d1 /internal/llm/provider.go
parentf14eb9199f4e1aee49594e590c08996244bb77b3 (diff)
feat: add OpenRouter providerv0.15.0
Diffstat (limited to 'internal/llm/provider.go')
-rw-r--r--internal/llm/provider.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/internal/llm/provider.go b/internal/llm/provider.go
index 84efaf9..b2c47e4 100644
--- a/internal/llm/provider.go
+++ b/internal/llm/provider.go
@@ -69,6 +69,10 @@ type Config struct {
OpenAIBaseURL string
OpenAIModel string
OpenAITemperature *float64
+ // OpenRouter options
+ OpenRouterBaseURL string
+ OpenRouterModel string
+ OpenRouterTemperature *float64
// Ollama options
OllamaBaseURL string
OllamaModel string
@@ -82,7 +86,7 @@ type Config struct {
// NewFromConfig creates an LLM client using only the supplied configuration.
// The OpenAI API key is supplied separately and may be read from the environment
// by the caller; other environment-based configuration is not used.
-func NewFromConfig(cfg Config, openAIAPIKey, copilotAPIKey string) (Client, error) {
+func NewFromConfig(cfg Config, openAIAPIKey, openRouterAPIKey, copilotAPIKey string) (Client, error) {
p := strings.ToLower(strings.TrimSpace(cfg.Provider))
if p == "" {
p = "openai"
@@ -112,6 +116,15 @@ func NewFromConfig(cfg Config, openAIAPIKey, copilotAPIKey string) (Client, erro
cfg.OpenAITemperature = &v
}
return newOpenAI(cfg.OpenAIBaseURL, cfg.OpenAIModel, openAIAPIKey, cfg.OpenAITemperature), nil
+ case "openrouter":
+ if strings.TrimSpace(openRouterAPIKey) == "" {
+ return nil, errors.New("missing OPENROUTER_API_KEY for provider openrouter")
+ }
+ if cfg.OpenRouterTemperature == nil {
+ t := 0.2
+ cfg.OpenRouterTemperature = &t
+ }
+ return newOpenRouter(cfg.OpenRouterBaseURL, cfg.OpenRouterModel, openRouterAPIKey, cfg.OpenRouterTemperature), nil
case "ollama":
if cfg.OllamaTemperature == nil {
t := 0.2