fix: prevent DefaultConfig template values from leaking into user model_list entries
This commit is contained in:
parent
8774526616
commit
0d761ca608
1 changed files with 14 additions and 0 deletions
|
|
@ -499,6 +499,20 @@ func LoadConfig(path string) (*Config, error) {
|
||||||
return nil, err
|
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 {
|
if err := json.Unmarshal(data, cfg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue