mirror of
https://github.com/lukaszraczylo/mcp-captcharesolver.git
synced 2026-10-20 01:27:53 +00:00
feat(llm): provider factory with per-provider default base URLs
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package llm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/lukaszraczylo/captcha-solver-mcp/internal/config"
|
||||
)
|
||||
|
||||
// New constructs the configured provider Client.
|
||||
func New(cfg config.Config) (Client, error) {
|
||||
hc := &http.Client{Timeout: cfg.Timeout}
|
||||
switch cfg.Provider {
|
||||
case "anthropic":
|
||||
base := cfg.BaseURL
|
||||
if base == "" {
|
||||
base = "https://api.anthropic.com"
|
||||
}
|
||||
return &anthropicClient{http: hc, base: base, key: cfg.APIKey, model: cfg.Model, maxTokens: cfg.MaxTokens}, nil
|
||||
case "openai":
|
||||
base := cfg.BaseURL
|
||||
if base == "" {
|
||||
base = "https://api.openai.com"
|
||||
}
|
||||
return &openAIClient{http: hc, base: base, key: cfg.APIKey, model: cfg.Model, audioModel: cfg.AudioModel, maxTokens: cfg.MaxTokens}, nil
|
||||
case "openai-compatible":
|
||||
if cfg.BaseURL == "" {
|
||||
return nil, fmt.Errorf("openai-compatible requires CAPTCHA_LLM_BASE_URL")
|
||||
}
|
||||
return &openAIClient{http: hc, base: cfg.BaseURL, key: cfg.APIKey, model: cfg.Model, audioModel: cfg.AudioModel, maxTokens: cfg.MaxTokens}, nil
|
||||
case "gemini":
|
||||
base := cfg.BaseURL
|
||||
if base == "" {
|
||||
base = "https://generativelanguage.googleapis.com"
|
||||
}
|
||||
return &geminiClient{http: hc, base: base, key: cfg.APIKey, model: cfg.Model, audioModel: cfg.AudioModel, maxTokens: cfg.MaxTokens}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown provider %q", cfg.Provider)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user