mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
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:
@@ -583,20 +583,13 @@ func (c *Config) HasProvidersConfig() bool {
|
||||
}
|
||||
|
||||
// ValidateModelList validates all ModelConfig entries in the model_list.
|
||||
// It checks that each model_name/model combination is valid and that
|
||||
// model_name is unique across all entries.
|
||||
// It checks that each model config is valid.
|
||||
// Note: Multiple entries with the same model_name are allowed for load balancing.
|
||||
func (c *Config) ValidateModelList() error {
|
||||
seen := make(map[string]int)
|
||||
for i := range c.ModelList {
|
||||
if err := c.ModelList[i].Validate(); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -195,18 +195,19 @@ func TestConfig_ValidateModelList(t *testing.T) {
|
||||
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{
|
||||
ModelList: []ModelConfig{
|
||||
{ModelName: "gpt-4", Model: "openai/gpt-4o", APIKey: "key1"},
|
||||
{ModelName: "gpt-4", Model: "openai/gpt-4-turbo", APIKey: "key2"},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
errMsg: "duplicate model_name",
|
||||
wantErr: false, // Changed: duplicates are allowed for load balancing
|
||||
},
|
||||
{
|
||||
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{
|
||||
ModelList: []ModelConfig{
|
||||
{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"},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
errMsg: "duplicate model_name \"model-a\"",
|
||||
wantErr: false, // Changed: duplicates are allowed for load balancing
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user