Merge pull request #724 from mqyang56/fix/model-list-default-value-leak

fix: prevent DefaultConfig template values from leaking into user model_list entries
This commit is contained in:
daming大铭
2026-02-24 19:43:23 +08:00
committed by GitHub
+14
View File
@@ -509,6 +509,20 @@ func LoadConfig(path string) (*Config, error) {
return nil, err
}
// Pre-scan the JSON to check how many model_list entries the user provided.
// Go's JSON decoder reuses existing slice backing-array elements rather than
// zero-initializing them, so fields absent from the user's JSON (e.g. api_base)
// would silently inherit values from the DefaultConfig template at the same
// index position. We only reset cfg.ModelList when the user actually provides
// entries; when count is 0 we keep DefaultConfig's built-in list as fallback.
var tmp Config
if err := json.Unmarshal(data, &tmp); err != nil {
return nil, err
}
if len(tmp.ModelList) > 0 {
cfg.ModelList = nil
}
if err := json.Unmarshal(data, cfg); err != nil {
return nil, err
}