Use getter/setter methods for API key access in ModelConfig

This commit is contained in:
uiyzzi 2026-03-23 15:51:13 +08:00
parent 53c6dd3812
commit 2d9517c655
6 changed files with 10 additions and 10 deletions

View file

@ -1199,11 +1199,11 @@ func TestModelConfig_ExtraBodyRoundTrip(t *testing.T) {
cfgPath := filepath.Join(dir, "config.json") cfgPath := filepath.Join(dir, "config.json")
cfg := &Config{ cfg := &Config{
ModelList: []ModelConfig{ ModelList: []*ModelConfig{
{ {
ModelName: "test-model", ModelName: "test-model",
Model: "openai/test", Model: "openai/test",
APIKey: "sk-test", apiKeys: []string{"sk-test"},
ExtraBody: map[string]any{"custom_field": "value", "num_field": 42}, ExtraBody: map[string]any{"custom_field": "value", "num_field": 42},
}, },
}, },

View file

@ -138,7 +138,7 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
case "minimax": case "minimax":
// Minimax requires reasoning_split: true in the request body // Minimax requires reasoning_split: true in the request body
if cfg.APIKey == "" && cfg.APIBase == "" { if cfg.APIKey() == "" && cfg.APIBase == "" {
return nil, "", fmt.Errorf("api_key or api_base is required for HTTP-based protocol %q", protocol) return nil, "", fmt.Errorf("api_key or api_base is required for HTTP-based protocol %q", protocol)
} }
apiBase := cfg.APIBase apiBase := cfg.APIBase
@ -153,7 +153,7 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
extraBody["reasoning_split"] = true extraBody["reasoning_split"] = true
} }
return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout(
cfg.APIKey, cfg.APIKey(),
apiBase, apiBase,
cfg.Proxy, cfg.Proxy,
cfg.MaxTokensField, cfg.MaxTokensField,

View file

@ -622,9 +622,9 @@ func TestCreateProviderFromConfig_MinimaxInjectsReasoningSplit(t *testing.T) {
cfg := &config.ModelConfig{ cfg := &config.ModelConfig{
ModelName: "test-minimax", ModelName: "test-minimax",
Model: "minimax/MiniMax-M2.5", Model: "minimax/MiniMax-M2.5",
APIKey: "test-key",
APIBase: server.URL, APIBase: server.URL,
} }
cfg.SetAPIKey("test-key")
provider, modelID, err := CreateProviderFromConfig(cfg) provider, modelID, err := CreateProviderFromConfig(cfg)
if err != nil { if err != nil {
@ -670,10 +670,10 @@ func TestCreateProviderFromConfig_MinimaxPreservesUserExtraBody(t *testing.T) {
cfg := &config.ModelConfig{ cfg := &config.ModelConfig{
ModelName: "test-minimax-custom", ModelName: "test-minimax-custom",
Model: "minimax/MiniMax-M2.5", Model: "minimax/MiniMax-M2.5",
APIKey: "test-key",
APIBase: server.URL, APIBase: server.URL,
ExtraBody: map[string]any{"custom_field": "test"}, ExtraBody: map[string]any{"custom_field": "test"},
} }
cfg.SetAPIKey("test-key")
provider, modelID, err := CreateProviderFromConfig(cfg) provider, modelID, err := CreateProviderFromConfig(cfg)
if err != nil { if err != nil {

View file

@ -17,7 +17,7 @@ export interface ModelInfo {
max_tokens_field?: string max_tokens_field?: string
request_timeout?: number request_timeout?: number
thinking_level?: string thinking_level?: string
extra_body?: Record<string, any> extra_body?: Record<string, unknown>
// Meta // Meta
configured: boolean configured: boolean
is_default: boolean is_default: boolean