remove unused provider-related code from HTTP provider implementation
This commit is contained in:
parent
feb098cf3f
commit
a87b039a69
1 changed files with 0 additions and 262 deletions
|
|
@ -1,9 +1,3 @@
|
||||||
// PicoClaw - Ultra-lightweight personal AI agent
|
|
||||||
// Inspired by and based on nanobot: https://github.com/HKUDS/nanobot
|
|
||||||
// License: MIT
|
|
||||||
//
|
|
||||||
// Copyright (c) 2026 PicoClaw contributors
|
|
||||||
|
|
||||||
package providers
|
package providers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -29,259 +23,3 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too
|
||||||
func (p *HTTPProvider) GetDefaultModel() string {
|
func (p *HTTPProvider) GetDefaultModel() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func createClaudeAuthProvider() (LLMProvider, error) {
|
|
||||||
cred, err := auth.GetCredential("anthropic")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("loading auth credentials: %w", err)
|
|
||||||
}
|
|
||||||
if cred == nil {
|
|
||||||
return nil, fmt.Errorf("no credentials for anthropic. Run: picoclaw auth login --provider anthropic")
|
|
||||||
}
|
|
||||||
return NewClaudeProviderWithTokenSource(cred.AccessToken, createClaudeTokenSource()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createCodexAuthProvider(enableWebSearch bool) (LLMProvider, error) {
|
|
||||||
cred, err := auth.GetCredential("openai")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("loading auth credentials: %w", err)
|
|
||||||
}
|
|
||||||
if cred == nil {
|
|
||||||
return nil, fmt.Errorf("no credentials for openai. Run: picoclaw auth login --provider openai")
|
|
||||||
}
|
|
||||||
p := NewCodexProviderWithTokenSource(cred.AccessToken, cred.AccountID, createCodexTokenSource())
|
|
||||||
p.enableWebSearch = enableWebSearch
|
|
||||||
return p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateProvider(cfg *config.Config) (LLMProvider, error) {
|
|
||||||
model := cfg.Agents.Defaults.Model
|
|
||||||
providerName := strings.ToLower(cfg.Agents.Defaults.Provider)
|
|
||||||
|
|
||||||
var apiKey, apiBase, proxy string
|
|
||||||
|
|
||||||
lowerModel := strings.ToLower(model)
|
|
||||||
|
|
||||||
// First, try to use explicitly configured provider
|
|
||||||
if providerName != "" {
|
|
||||||
switch providerName {
|
|
||||||
case "groq":
|
|
||||||
if cfg.Providers["groq"].APIKey != "" {
|
|
||||||
apiKey = cfg.Providers["groq"].APIKey
|
|
||||||
apiBase = cfg.Providers["groq"].APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.groq.com/openai/v1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "openai", "gpt":
|
|
||||||
if cfg.Providers["openai"].APIKey != "" || cfg.Providers["openai"].AuthMethod != "" {
|
|
||||||
if cfg.Providers["openai"].AuthMethod == "codex-cli" {
|
|
||||||
c := NewCodexProviderWithTokenSource("", "", CreateCodexCliTokenSource())
|
|
||||||
c.enableWebSearch = cfg.Providers["openai"].WebSearch
|
|
||||||
return c, nil
|
|
||||||
}
|
|
||||||
if cfg.Providers["openai"].AuthMethod == "oauth" || cfg.Providers["openai"].AuthMethod == "token" {
|
|
||||||
return createCodexAuthProvider(cfg.Providers["openai"].WebSearch)
|
|
||||||
}
|
|
||||||
apiKey = cfg.Providers["openai"].APIKey
|
|
||||||
apiBase = cfg.Providers["openai"].APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.openai.com/v1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "anthropic", "claude":
|
|
||||||
if cfg.Providers["anthropic"].APIKey != "" || cfg.Providers["anthropic"].AuthMethod != "" {
|
|
||||||
if cfg.Providers["anthropic"].AuthMethod == "oauth" || cfg.Providers["anthropic"].AuthMethod == "token" {
|
|
||||||
return createClaudeAuthProvider()
|
|
||||||
}
|
|
||||||
apiKey = cfg.Providers["anthropic"].APIKey
|
|
||||||
apiBase = cfg.Providers["anthropic"].APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.anthropic.com/v1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "openrouter":
|
|
||||||
if cfg.Providers["openrouter"].APIKey != "" {
|
|
||||||
apiKey = cfg.Providers["openrouter"].APIKey
|
|
||||||
if cfg.Providers["openrouter"].APIBase != "" {
|
|
||||||
apiBase = cfg.Providers["openrouter"].APIBase
|
|
||||||
} else {
|
|
||||||
apiBase = "https://openrouter.ai/api/v1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "zhipu", "glm":
|
|
||||||
if cfg.Providers["zhipu"].APIKey != "" {
|
|
||||||
apiKey = cfg.Providers["zhipu"].APIKey
|
|
||||||
apiBase = cfg.Providers["zhipu"].APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://open.bigmodel.cn/api/paas/v4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "gemini", "google":
|
|
||||||
if cfg.Providers["gemini"].APIKey != "" {
|
|
||||||
apiKey = cfg.Providers["gemini"].APIKey
|
|
||||||
apiBase = cfg.Providers["gemini"].APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://generativelanguage.googleapis.com/v1beta"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "vllm":
|
|
||||||
if cfg.Providers["vllm"].APIBase != "" {
|
|
||||||
apiKey = cfg.Providers["vllm"].APIKey
|
|
||||||
apiBase = cfg.Providers["vllm"].APIBase
|
|
||||||
}
|
|
||||||
case "shengsuanyun":
|
|
||||||
if cfg.Providers["shengsuanyun"].APIKey != "" {
|
|
||||||
apiKey = cfg.Providers["shengsuanyun"].APIKey
|
|
||||||
apiBase = cfg.Providers["shengsuanyun"].APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://router.shengsuanyun.com/api/v1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "claude-cli", "claudecode", "claude-code":
|
|
||||||
workspace := cfg.WorkspacePath()
|
|
||||||
if workspace == "" {
|
|
||||||
workspace = "."
|
|
||||||
}
|
|
||||||
return NewClaudeCliProvider(workspace), nil
|
|
||||||
case "codex-cli", "codex-code":
|
|
||||||
workspace := cfg.WorkspacePath()
|
|
||||||
if workspace == "" {
|
|
||||||
workspace = "."
|
|
||||||
}
|
|
||||||
return NewCodexCliProvider(workspace), nil
|
|
||||||
case "deepseek":
|
|
||||||
if cfg.Providers["deepseek"].APIKey != "" {
|
|
||||||
apiKey = cfg.Providers["deepseek"].APIKey
|
|
||||||
apiBase = cfg.Providers["deepseek"].APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.deepseek.com/v1"
|
|
||||||
}
|
|
||||||
if model != "deepseek-chat" && model != "deepseek-reasoner" {
|
|
||||||
model = "deepseek-chat"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "github_copilot", "copilot":
|
|
||||||
if cfg.Providers["githubcopilot"].APIBase != "" {
|
|
||||||
apiBase = cfg.Providers["githubcopilot"].APIBase
|
|
||||||
} else {
|
|
||||||
apiBase = "localhost:4321"
|
|
||||||
}
|
|
||||||
return NewGitHubCopilotProvider(apiBase, cfg.Providers["githubcopilot"].ConnectMode, model)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: detect provider from model name
|
|
||||||
if apiKey == "" && apiBase == "" {
|
|
||||||
switch {
|
|
||||||
case (strings.Contains(lowerModel, "kimi") || strings.Contains(lowerModel, "moonshot") || strings.HasPrefix(model, "moonshot/")) && cfg.Providers["moonshot"].APIKey != "":
|
|
||||||
apiKey = cfg.Providers["moonshot"].APIKey
|
|
||||||
apiBase = cfg.Providers["moonshot"].APIBase
|
|
||||||
proxy = cfg.Providers["moonshot"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.moonshot.cn/v1"
|
|
||||||
}
|
|
||||||
|
|
||||||
case strings.HasPrefix(model, "openrouter/") || strings.HasPrefix(model, "anthropic/") || strings.HasPrefix(model, "openai/") || strings.HasPrefix(model, "meta-llama/") || strings.HasPrefix(model, "deepseek/") || strings.HasPrefix(model, "google/"):
|
|
||||||
apiKey = cfg.Providers["openrouter"].APIKey
|
|
||||||
proxy = cfg.Providers["openrouter"].Proxy
|
|
||||||
if cfg.Providers["openrouter"].APIBase != "" {
|
|
||||||
apiBase = cfg.Providers["openrouter"].APIBase
|
|
||||||
} else {
|
|
||||||
apiBase = "https://openrouter.ai/api/v1"
|
|
||||||
}
|
|
||||||
|
|
||||||
case (strings.Contains(lowerModel, "claude") || strings.HasPrefix(model, "anthropic/")) && (cfg.Providers["anthropic"].APIKey != "" || cfg.Providers["anthropic"].AuthMethod != ""):
|
|
||||||
if cfg.Providers["anthropic"].AuthMethod == "oauth" || cfg.Providers["anthropic"].AuthMethod == "token" {
|
|
||||||
return createClaudeAuthProvider()
|
|
||||||
}
|
|
||||||
apiKey = cfg.Providers["anthropic"].APIKey
|
|
||||||
apiBase = cfg.Providers["anthropic"].APIBase
|
|
||||||
proxy = cfg.Providers["anthropic"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.anthropic.com/v1"
|
|
||||||
}
|
|
||||||
|
|
||||||
case (strings.Contains(lowerModel, "gpt") || strings.HasPrefix(model, "openai/")) && (cfg.Providers["openai"].APIKey != "" || cfg.Providers["openai"].AuthMethod != ""):
|
|
||||||
if cfg.Providers["openai"].AuthMethod == "oauth" || cfg.Providers["openai"].AuthMethod == "token" {
|
|
||||||
return createCodexAuthProvider(cfg.Providers["openai"].WebSearch)
|
|
||||||
}
|
|
||||||
apiKey = cfg.Providers["openai"].APIKey
|
|
||||||
apiBase = cfg.Providers["openai"].APIBase
|
|
||||||
proxy = cfg.Providers["openai"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.openai.com/v1"
|
|
||||||
}
|
|
||||||
|
|
||||||
case (strings.Contains(lowerModel, "gemini") || strings.HasPrefix(model, "google/")) && cfg.Providers["gemini"].APIKey != "":
|
|
||||||
apiKey = cfg.Providers["gemini"].APIKey
|
|
||||||
apiBase = cfg.Providers["gemini"].APIBase
|
|
||||||
proxy = cfg.Providers["gemini"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://generativelanguage.googleapis.com/v1beta"
|
|
||||||
}
|
|
||||||
|
|
||||||
case (strings.Contains(lowerModel, "glm") || strings.Contains(lowerModel, "zhipu") || strings.Contains(lowerModel, "zai")) && cfg.Providers["zhipu"].APIKey != "":
|
|
||||||
apiKey = cfg.Providers["zhipu"].APIKey
|
|
||||||
apiBase = cfg.Providers["zhipu"].APIBase
|
|
||||||
proxy = cfg.Providers["zhipu"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://open.bigmodel.cn/api/paas/v4"
|
|
||||||
}
|
|
||||||
|
|
||||||
case (strings.Contains(lowerModel, "groq") || strings.HasPrefix(model, "groq/")) && cfg.Providers["groq"].APIKey != "":
|
|
||||||
apiKey = cfg.Providers["groq"].APIKey
|
|
||||||
apiBase = cfg.Providers["groq"].APIBase
|
|
||||||
proxy = cfg.Providers["groq"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.groq.com/openai/v1"
|
|
||||||
}
|
|
||||||
|
|
||||||
case (strings.Contains(lowerModel, "nvidia") || strings.HasPrefix(model, "nvidia/")) && cfg.Providers["nvidia"].APIKey != "":
|
|
||||||
apiKey = cfg.Providers["nvidia"].APIKey
|
|
||||||
apiBase = cfg.Providers["nvidia"].APIBase
|
|
||||||
proxy = cfg.Providers["nvidia"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://integrate.api.nvidia.com/v1"
|
|
||||||
}
|
|
||||||
case (strings.Contains(lowerModel, "ollama") || strings.HasPrefix(model, "ollama/")) && cfg.Providers["ollama"].APIKey != "":
|
|
||||||
fmt.Println("Ollama provider selected based on model name prefix")
|
|
||||||
apiKey = cfg.Providers["ollama"].APIKey
|
|
||||||
apiBase = cfg.Providers["ollama"].APIBase
|
|
||||||
proxy = cfg.Providers["ollama"].Proxy
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "http://localhost:11434/v1"
|
|
||||||
}
|
|
||||||
fmt.Println("Ollama apiBase:", apiBase)
|
|
||||||
case cfg.Providers["vllm"].APIBase != "":
|
|
||||||
apiKey = cfg.Providers["vllm"].APIKey
|
|
||||||
apiBase = cfg.Providers["vllm"].APIBase
|
|
||||||
proxy = cfg.Providers["vllm"].Proxy
|
|
||||||
|
|
||||||
default:
|
|
||||||
if cfg.Providers["openrouter"].APIKey != "" {
|
|
||||||
apiKey = cfg.Providers["openrouter"].APIKey
|
|
||||||
proxy = cfg.Providers["openrouter"].Proxy
|
|
||||||
if cfg.Providers["openrouter"].APIBase != "" {
|
|
||||||
apiBase = cfg.Providers["openrouter"].APIBase
|
|
||||||
} else {
|
|
||||||
apiBase = "https://openrouter.ai/api/v1"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("no API key configured for model: %s", model)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if apiKey == "" && !strings.HasPrefix(model, "bedrock/") {
|
|
||||||
return nil, fmt.Errorf("no API key configured for provider (model: %s)", model)
|
|
||||||
}
|
|
||||||
|
|
||||||
if apiBase == "" {
|
|
||||||
return nil, fmt.Errorf("no API base configured for provider (model: %s)", model)
|
|
||||||
}
|
|
||||||
|
|
||||||
return NewHTTPProvider(apiKey, apiBase, proxy), nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue