This PR adds support for custom OpenAI-compatible endpoints, allowing users to connect to any OpenAI-compatible API such as LM Studio, llama.cpp, vLLM, Ollama, and more.
- **Configuration** (`pkg/config/config.go`)
- Added `Custom` field to `ProvidersConfig` struct
- Initialized `Custom` default value in `DefaultConfig()` function
- **Provider Factory** (`pkg/providers/factory.go`)
- Added explicit `"custom"` provider configuration support in `resolveProviderSelection` function
- Added custom provider auto-detection in fallback logic
Add the following to your configuration file:
```json
{
"agents": {
"defaults": {
"provider": "custom",
"model": "your-model-name"
}
},
"providers": {
"custom": {
"api_key": "your-api-key",
"api_base": "https://api.your-provider.com/v1",
"proxy": ""
}
}
}
```
This commit is contained in:
parent
56a060ff61
commit
86ff42b4fa
2 changed files with 12 additions and 0 deletions
|
|
@ -263,6 +263,7 @@ type ProvidersConfig struct {
|
||||||
ShengSuanYun ProviderConfig `json:"shengsuanyun"`
|
ShengSuanYun ProviderConfig `json:"shengsuanyun"`
|
||||||
DeepSeek ProviderConfig `json:"deepseek"`
|
DeepSeek ProviderConfig `json:"deepseek"`
|
||||||
GitHubCopilot ProviderConfig `json:"github_copilot"`
|
GitHubCopilot ProviderConfig `json:"github_copilot"`
|
||||||
|
Custom ProviderConfig `json:"custom"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProviderConfig struct {
|
type ProviderConfig struct {
|
||||||
|
|
@ -411,6 +412,7 @@ func DefaultConfig() *Config {
|
||||||
Nvidia: ProviderConfig{},
|
Nvidia: ProviderConfig{},
|
||||||
Moonshot: ProviderConfig{},
|
Moonshot: ProviderConfig{},
|
||||||
ShengSuanYun: ProviderConfig{},
|
ShengSuanYun: ProviderConfig{},
|
||||||
|
Custom: ProviderConfig{},
|
||||||
},
|
},
|
||||||
Gateway: GatewayConfig{
|
Gateway: GatewayConfig{
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,12 @@ func resolveProviderSelection(cfg *config.Config) (providerSelection, error) {
|
||||||
// First, prefer explicit provider configuration.
|
// First, prefer explicit provider configuration.
|
||||||
if providerName != "" {
|
if providerName != "" {
|
||||||
switch providerName {
|
switch providerName {
|
||||||
|
case "custom":
|
||||||
|
if cfg.Providers.Custom.APIBase != "" {
|
||||||
|
sel.apiKey = cfg.Providers.Custom.APIKey
|
||||||
|
sel.apiBase = cfg.Providers.Custom.APIBase
|
||||||
|
sel.proxy = cfg.Providers.Custom.Proxy
|
||||||
|
}
|
||||||
case "groq":
|
case "groq":
|
||||||
if cfg.Providers.Groq.APIKey != "" {
|
if cfg.Providers.Groq.APIKey != "" {
|
||||||
sel.apiKey = cfg.Providers.Groq.APIKey
|
sel.apiKey = cfg.Providers.Groq.APIKey
|
||||||
|
|
@ -214,6 +220,10 @@ func resolveProviderSelection(cfg *config.Config) (providerSelection, error) {
|
||||||
// Fallback: infer provider from model and configured keys.
|
// Fallback: infer provider from model and configured keys.
|
||||||
if sel.apiKey == "" && sel.apiBase == "" {
|
if sel.apiKey == "" && sel.apiBase == "" {
|
||||||
switch {
|
switch {
|
||||||
|
case cfg.Providers.Custom.APIBase != "":
|
||||||
|
sel.apiKey = cfg.Providers.Custom.APIKey
|
||||||
|
sel.apiBase = cfg.Providers.Custom.APIBase
|
||||||
|
sel.proxy = cfg.Providers.Custom.Proxy
|
||||||
case (strings.Contains(lowerModel, "kimi") || strings.Contains(lowerModel, "moonshot") || strings.HasPrefix(model, "moonshot/")) && cfg.Providers.Moonshot.APIKey != "":
|
case (strings.Contains(lowerModel, "kimi") || strings.Contains(lowerModel, "moonshot") || strings.HasPrefix(model, "moonshot/")) && cfg.Providers.Moonshot.APIKey != "":
|
||||||
sel.apiKey = cfg.Providers.Moonshot.APIKey
|
sel.apiKey = cfg.Providers.Moonshot.APIKey
|
||||||
sel.apiBase = cfg.Providers.Moonshot.APIBase
|
sel.apiBase = cfg.Providers.Moonshot.APIBase
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue