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 608ec6d329
commit 79df938696
6 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -939,8 +939,8 @@ type ModelConfig struct {
RPM int `json:"rpm,omitempty"` // Requests per minute limit
MaxTokensField string `json:"max_tokens_field,omitempty"` // Field name for max tokens (e.g., "max_completion_tokens")
RequestTimeout int `json:"request_timeout,omitempty"`
ThinkingLevel string `json:"thinking_level,omitempty"` // Extended thinking: off|low|medium|high|xhigh|adaptive
ExtraBody map[string]any `json:"extra_body,omitempty"` // Additional fields to inject into request body
ThinkingLevel string `json:"thinking_level,omitempty"` // Extended thinking: off|low|medium|high|xhigh|adaptive
ExtraBody map[string]any `json:"extra_body,omitempty"` // Additional fields to inject into request body
// from security
secModelName string
+2 -2
View File
@@ -1199,11 +1199,11 @@ func TestModelConfig_ExtraBodyRoundTrip(t *testing.T) {
cfgPath := filepath.Join(dir, "config.json")
cfg := &Config{
ModelList: []ModelConfig{
ModelList: []*ModelConfig{
{
ModelName: "test-model",
Model: "openai/test",
APIKey: "sk-test",
apiKeys: []string{"sk-test"},
ExtraBody: map[string]any{"custom_field": "value", "num_field": 42},
},
},
+1 -1
View File
@@ -339,7 +339,7 @@ func DefaultConfig() *Config {
ModelName: "MiniMax-M2.5",
Model: "minimax/MiniMax-M2.5",
APIBase: "https://api.minimaxi.com/v1",
ExtraBody: map[string]any{"reasoning_split": true},
ExtraBody: map[string]any{"reasoning_split": true},
},
// LongCat - https://longcat.chat/platform
+2 -2
View File
@@ -138,7 +138,7 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
case "minimax":
// 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)
}
apiBase := cfg.APIBase
@@ -153,7 +153,7 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
extraBody["reasoning_split"] = true
}
return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout(
cfg.APIKey,
cfg.APIKey(),
apiBase,
cfg.Proxy,
cfg.MaxTokensField,
+2 -2
View File
@@ -622,9 +622,9 @@ func TestCreateProviderFromConfig_MinimaxInjectsReasoningSplit(t *testing.T) {
cfg := &config.ModelConfig{
ModelName: "test-minimax",
Model: "minimax/MiniMax-M2.5",
APIKey: "test-key",
APIBase: server.URL,
}
cfg.SetAPIKey("test-key")
provider, modelID, err := CreateProviderFromConfig(cfg)
if err != nil {
@@ -670,10 +670,10 @@ func TestCreateProviderFromConfig_MinimaxPreservesUserExtraBody(t *testing.T) {
cfg := &config.ModelConfig{
ModelName: "test-minimax-custom",
Model: "minimax/MiniMax-M2.5",
APIKey: "test-key",
APIBase: server.URL,
ExtraBody: map[string]any{"custom_field": "test"},
}
cfg.SetAPIKey("test-key")
provider, modelID, err := CreateProviderFromConfig(cfg)
if err != nil {
+1 -1
View File
@@ -17,7 +17,7 @@ export interface ModelInfo {
max_tokens_field?: string
request_timeout?: number
thinking_level?: string
extra_body?: Record<string, any>
extra_body?: Record<string, unknown>
// Meta
configured: boolean
is_default: boolean