fix: prevent DefaultConfig template values from leaking into user model_list entries

This commit is contained in:
yangmanqing
2026-02-24 17:57:28 +08:00
parent 8774526616
commit 0d761ca608
+14
View File
@@ -499,6 +499,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
}