Use getter/setter methods for API key access in ModelConfig
This commit is contained in:
parent
608ec6d329
commit
79df938696
6 changed files with 10 additions and 10 deletions
|
|
@ -939,8 +939,8 @@ type ModelConfig struct {
|
||||||
RPM int `json:"rpm,omitempty"` // Requests per minute limit
|
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")
|
MaxTokensField string `json:"max_tokens_field,omitempty"` // Field name for max tokens (e.g., "max_completion_tokens")
|
||||||
RequestTimeout int `json:"request_timeout,omitempty"`
|
RequestTimeout int `json:"request_timeout,omitempty"`
|
||||||
ThinkingLevel string `json:"thinking_level,omitempty"` // Extended thinking: off|low|medium|high|xhigh|adaptive
|
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
|
ExtraBody map[string]any `json:"extra_body,omitempty"` // Additional fields to inject into request body
|
||||||
|
|
||||||
// from security
|
// from security
|
||||||
secModelName string
|
secModelName string
|
||||||
|
|
|
||||||
|
|
@ -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},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -339,7 +339,7 @@ func DefaultConfig() *Config {
|
||||||
ModelName: "MiniMax-M2.5",
|
ModelName: "MiniMax-M2.5",
|
||||||
Model: "minimax/MiniMax-M2.5",
|
Model: "minimax/MiniMax-M2.5",
|
||||||
APIBase: "https://api.minimaxi.com/v1",
|
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
|
// LongCat - https://longcat.chat/platform
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue