Refactor KnowledgeBase loading process to compute features after provider loading

- Moved the computation of features in the Config struct to occur after loading providers, ensuring that all necessary data is available for accurate feature computation.
- Updated comments for clarity regarding the loading sequence of providers and feature computation.
This commit is contained in:
Max 2025-08-09 17:13:52 +08:00
parent 4bdd921d4c
commit 65d04bb583
2 changed files with 11 additions and 7 deletions

View file

@ -41,6 +41,12 @@ func Load(appConfig config.Config) (*KnowledgeBase, error) {
return nil, nil
}
// Load providers from directories first
providers, err := kbtypes.LoadProviders("kb")
if err != nil {
return nil, err
}
// Parse the configuration
var config kbtypes.Config
raw, err := application.App.Read(filepath.Join("kb", "kb.yao"))
@ -53,13 +59,12 @@ func Load(appConfig config.Config) (*KnowledgeBase, error) {
return nil, err
}
// Load providers from directories
providers, err := kbtypes.LoadProviders("kb")
if err != nil {
return nil, err
}
// Assign providers to config
config.Providers = providers
// Compute features after both config and providers are loaded
config.Features = config.ComputeFeatures()
// Set global configurations for providers to use
kbtypes.SetGlobalPDF(config.PDF)
kbtypes.SetGlobalFFmpeg(config.FFmpeg)

View file

@ -323,8 +323,7 @@ func (c *Config) UnmarshalJSON(data []byte) error {
c.Uploader = "__yao.attachment"
}
// Compute features after parsing and resolving env vars
c.Features = c.ComputeFeatures()
// Note: Features will be computed later after providers are loaded
return nil
}