feat: add Agnes AI as default provider, support multi-provider switching
- Default provider changed from Zhipu to Agnes AI (agnes-2.0-flash) - Add --provider flag: agnes (default), zhipu, custom - Add AGNES_API_KEY env var support (still compatible with ZHIPU_API_KEY) - Add provider presets system for easy switching between AI backends - Add .gitignore to prevent config.json with API keys from being committed - Update usage examples Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
49
config.go
49
config.go
@@ -10,16 +10,48 @@ import (
|
||||
|
||||
// Config holds the application configuration.
|
||||
type Config struct {
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
BaseURL string `json:"base_url"`
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
BaseURL string `json:"base_url"`
|
||||
Provider string `json:"provider"` // "agnes" or "zhipu" or "custom"
|
||||
}
|
||||
|
||||
// DefaultConfig returns a Config with sensible defaults.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
// Provider presets
|
||||
var providerPresets = map[string]struct {
|
||||
Model string
|
||||
BaseURL string
|
||||
}{
|
||||
"agnes": {
|
||||
Model: "agnes-2.0-flash",
|
||||
BaseURL: "https://apihub.agnes-ai.com/v1/chat/completions",
|
||||
},
|
||||
"zhipu": {
|
||||
Model: "glm-4.6v-flash",
|
||||
BaseURL: "https://open.bigmodel.cn/api/paas/v4/chat/completions",
|
||||
},
|
||||
}
|
||||
|
||||
// DefaultConfig returns a Config with sensible defaults (Agnes AI).
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Provider: "agnes",
|
||||
Model: "agnes-2.0-flash",
|
||||
BaseURL: "https://apihub.agnes-ai.com/v1/chat/completions",
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyProvider applies a named provider preset, respecting user overrides.
|
||||
func (c *Config) ApplyProvider(provider string) {
|
||||
if preset, ok := providerPresets[provider]; ok {
|
||||
c.Provider = provider
|
||||
// Only override model/baseURL if user hasn't set custom ones
|
||||
if c.Model == "" || c.Model == "agnes-2.0-flash" || c.Model == "glm-4.6v-flash" {
|
||||
c.Model = preset.Model
|
||||
}
|
||||
if c.BaseURL == "" || c.BaseURL == "https://apihub.agnes-ai.com/v1/chat/completions" ||
|
||||
c.BaseURL == "https://open.bigmodel.cn/api/paas/v4/chat/completions" {
|
||||
c.BaseURL = preset.BaseURL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +85,9 @@ func LoadConfig(flagKey, configPath string) (*Config, error) {
|
||||
}
|
||||
|
||||
// Override with environment variable
|
||||
if envKey := os.Getenv("AGNES_API_KEY"); envKey != "" {
|
||||
cfg.APIKey = envKey
|
||||
}
|
||||
if envKey := os.Getenv("ZHIPU_API_KEY"); envKey != "" {
|
||||
cfg.APIKey = envKey
|
||||
}
|
||||
@@ -65,7 +100,7 @@ func LoadConfig(flagKey, configPath string) (*Config, error) {
|
||||
if cfg.APIKey == "" {
|
||||
return cfg, fmt.Errorf("API key not configured. Set it via:\n" +
|
||||
" 1. --apikey flag\n" +
|
||||
" 2. ZHIPU_API_KEY environment variable\n" +
|
||||
" 2. AGNES_API_KEY environment variable\n" +
|
||||
" 3. config.json file in the tools directory")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user