fix(config): allow duplicate model_name for load balancing
Remove duplicate model_name check in ValidateModelList to support load balancing feature where multiple configs can share the same model_name for round-robin selection. Update tests to reflect the new behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a1d694b8f1
commit
7572e3b95d
2 changed files with 8 additions and 15 deletions
|
|
@ -583,20 +583,13 @@ func (c *Config) HasProvidersConfig() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateModelList validates all ModelConfig entries in the model_list.
|
// ValidateModelList validates all ModelConfig entries in the model_list.
|
||||||
// It checks that each model_name/model combination is valid and that
|
// It checks that each model config is valid.
|
||||||
// model_name is unique across all entries.
|
// Note: Multiple entries with the same model_name are allowed for load balancing.
|
||||||
func (c *Config) ValidateModelList() error {
|
func (c *Config) ValidateModelList() error {
|
||||||
seen := make(map[string]int)
|
|
||||||
for i := range c.ModelList {
|
for i := range c.ModelList {
|
||||||
if err := c.ModelList[i].Validate(); err != nil {
|
if err := c.ModelList[i].Validate(); err != nil {
|
||||||
return fmt.Errorf("model_list[%d]: %w", i, err)
|
return fmt.Errorf("model_list[%d]: %w", i, err)
|
||||||
}
|
}
|
||||||
// Check for duplicate model_name
|
|
||||||
name := c.ModelList[i].ModelName
|
|
||||||
if prevIdx, exists := seen[name]; exists {
|
|
||||||
return fmt.Errorf("model_list: duplicate model_name %q at index %d and %d", name, prevIdx, i)
|
|
||||||
}
|
|
||||||
seen[name] = i
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,18 +195,19 @@ func TestConfig_ValidateModelList(t *testing.T) {
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "duplicate model_name",
|
// Load balancing: multiple entries with same model_name are allowed
|
||||||
|
name: "duplicate model_name for load balancing",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
ModelList: []ModelConfig{
|
ModelList: []ModelConfig{
|
||||||
{ModelName: "gpt-4", Model: "openai/gpt-4o", APIKey: "key1"},
|
{ModelName: "gpt-4", Model: "openai/gpt-4o", APIKey: "key1"},
|
||||||
{ModelName: "gpt-4", Model: "openai/gpt-4-turbo", APIKey: "key2"},
|
{ModelName: "gpt-4", Model: "openai/gpt-4-turbo", APIKey: "key2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: false, // Changed: duplicates are allowed for load balancing
|
||||||
errMsg: "duplicate model_name",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "duplicate model_name non-adjacent",
|
// Load balancing: non-adjacent entries with same model_name are also allowed
|
||||||
|
name: "duplicate model_name non-adjacent for load balancing",
|
||||||
config: &Config{
|
config: &Config{
|
||||||
ModelList: []ModelConfig{
|
ModelList: []ModelConfig{
|
||||||
{ModelName: "model-a", Model: "openai/gpt-4o"},
|
{ModelName: "model-a", Model: "openai/gpt-4o"},
|
||||||
|
|
@ -214,8 +215,7 @@ func TestConfig_ValidateModelList(t *testing.T) {
|
||||||
{ModelName: "model-a", Model: "openai/gpt-4-turbo"},
|
{ModelName: "model-a", Model: "openai/gpt-4-turbo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: false, // Changed: duplicates are allowed for load balancing
|
||||||
errMsg: "duplicate model_name \"model-a\"",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue