Merge pull request #14 from TanLuong/fix-config-model-list-override-13448010885405533147

Fix `model_list` user override when explicitly empty
This commit is contained in:
Nhat Tan 2026-03-27 10:45:05 +07:00 committed by GitHub
commit e38e2a3a63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 6 deletions

View file

@ -1048,10 +1048,10 @@ type SearXNGConfig struct {
} }
type GLMSearchConfig struct { type GLMSearchConfig struct {
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_GLM_ENABLED"` Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_GLM_ENABLED"`
apiKey string apiKey string
secDirty bool secDirty bool
BaseURL string `json:"base_url" env:"PICOCLAW_TOOLS_WEB_GLM_BASE_URL"` BaseURL string `json:"base_url" env:"PICOCLAW_TOOLS_WEB_GLM_BASE_URL"`
// SearchEngine specifies the search backend: "search_std" (default), // SearchEngine specifies the search backend: "search_std" (default),
// "search_pro", "search_pro_sogou", or "search_pro_quark". // "search_pro", "search_pro_sogou", or "search_pro_quark".
SearchEngine string `json:"search_engine" env:"PICOCLAW_TOOLS_WEB_GLM_SEARCH_ENGINE"` SearchEngine string `json:"search_engine" env:"PICOCLAW_TOOLS_WEB_GLM_SEARCH_ENGINE"`

View file

@ -521,11 +521,13 @@ func loadConfig(data []byte) (*Config, error) {
// would silently inherit values from the DefaultConfig template at the same // would silently inherit values from the DefaultConfig template at the same
// index position. We only reset cfg.ModelList when the user actually provides // 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. // entries; when count is 0 we keep DefaultConfig's built-in list as fallback.
var tmp Config var tmp struct {
ModelList json.RawMessage `json:"model_list"`
}
if err := json.Unmarshal(data, &tmp); err != nil { if err := json.Unmarshal(data, &tmp); err != nil {
return nil, err return nil, err
} }
if len(tmp.ModelList) > 0 { if tmp.ModelList != nil {
cfg.ModelList = nil cfg.ModelList = nil
} }

View file

@ -0,0 +1,21 @@
--- pkg/config/migration.go
+++ pkg/config/migration.go
@@ -515,11 +515,16 @@
// 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
+ var tmp struct {
+ ModelList json.RawMessage `json:"model_list"`
+ }
if err := json.Unmarshal(data, &tmp); err != nil {
return nil, err
}
- if len(tmp.ModelList) > 0 {
+ if tmp.ModelList != nil {
+ // User explicitly defined model_list, even if it's empty []
cfg.ModelList = nil
}
if err := json.Unmarshal(data, cfg); err != nil {