@@ -16,6 +16,26 @@ import (
1616 "github.com/docker/cagent/pkg/tools"
1717)
1818
19+ // Alias defines the configuration for a provider alias
20+ type Alias struct {
21+ ApiType string // The actual API type to use (openai, anthropic, etc.)
22+ BaseURL string // Default base URL for the provider
23+ TokenEnvVar string // Environment variable name for the API token
24+ }
25+
26+ // ProviderAliases maps provider names to their corresponding configurations
27+ var ProviderAliases = map [string ]Alias {
28+ "requesty" : {
29+ ApiType : "openai" ,
30+ BaseURL : "https://router.requesty.ai/v1" ,
31+ TokenEnvVar : "REQUESTY_API_KEY" ,
32+ },
33+ "azure" : {
34+ ApiType : "openai" ,
35+ TokenEnvVar : "AZURE_API_KEY" ,
36+ },
37+ }
38+
1939// Provider defines the interface for model providers
2040type Provider interface {
2141 // ID returns the model provider ID
@@ -37,21 +57,69 @@ type Provider interface {
3757func New (ctx context.Context , cfg * latest.ModelConfig , env environment.Provider , opts ... options.Opt ) (Provider , error ) {
3858 slog .Debug ("Creating model provider" , "type" , cfg .Provider , "model" , cfg .Model )
3959
40- switch cfg .Provider {
60+ // Apply provider alias defaults to the config
61+ enhancedCfg := applyProviderDefaults (cfg )
62+ apiType := ""
63+ if alias , exists := ProviderAliases [cfg .Provider ]; exists {
64+ apiType = alias .ApiType
65+ }
66+
67+ // Resolve the actual API type from aliases or direct specification
68+ providerType := resolveProviderType (cfg .Provider , apiType )
69+
70+ switch providerType {
4171 case "openai" :
42- return openai .NewClient (ctx , cfg , env , opts ... )
72+ return openai .NewClient (ctx , enhancedCfg , env , opts ... )
4373
4474 case "anthropic" :
45- return anthropic .NewClient (ctx , cfg , env , opts ... )
75+ return anthropic .NewClient (ctx , enhancedCfg , env , opts ... )
4676
4777 case "google" :
48- return gemini .NewClient (ctx , cfg , env , opts ... )
78+ return gemini .NewClient (ctx , enhancedCfg , env , opts ... )
4979
5080 case "dmr" :
51- return dmr .NewClient (ctx , cfg , opts ... )
81+ return dmr .NewClient (ctx , enhancedCfg , opts ... )
5282
5383 default :
54- slog .Error ("Unknown provider type" , "type" , cfg . Provider )
55- return nil , fmt .Errorf ("unknown provider type: %s" , cfg . Provider )
84+ slog .Error ("Unknown provider type" , "type" , providerType )
85+ return nil , fmt .Errorf ("unknown provider type: %s" , providerType )
5686 }
5787}
88+
89+ // applyProviderDefaults applies default configuration from provider aliases to the model config
90+ // This sets default base URLs and token keys if not already specified
91+ func applyProviderDefaults (cfg * latest.ModelConfig ) * latest.ModelConfig {
92+ // Create a copy to avoid modifying the original
93+ enhancedCfg := * cfg
94+
95+ // Check if provider has alias configuration
96+ if alias , exists := ProviderAliases [cfg .Provider ]; exists {
97+ // Set default base URL if not already specified
98+ if enhancedCfg .BaseURL == "" && alias .BaseURL != "" {
99+ enhancedCfg .BaseURL = alias .BaseURL
100+ }
101+
102+ // Set default token key if not already specified
103+ if enhancedCfg .TokenKey == "" && alias .TokenEnvVar != "" {
104+ enhancedCfg .TokenKey = alias .TokenEnvVar
105+ }
106+ }
107+
108+ return & enhancedCfg
109+ }
110+
111+ // resolveProviderType resolves the actual API type from the provider name and optional apiType
112+ func resolveProviderType (provider , apiType string ) string {
113+ // If apiType is explicitly provided, use it
114+ if apiType != "" {
115+ return apiType
116+ }
117+
118+ // Check if provider has an alias mapping
119+ if resolved , exists := ProviderAliases [provider ]; exists {
120+ return resolved .ApiType
121+ }
122+
123+ // Fall back to the provider name itself
124+ return provider
125+ }
0 commit comments