feat(builtin-models): add YAML-based declarative config with ${ENV} interpolation

Allow built-in models to be declared in config/builtin_models.yaml
instead of inserting rows via SQL. On every startup the file is read
and each entry is UPSERT-ed into the models table (is_builtin=true)
by stable id.

Any string field may reference an environment variable with ${NAME}.
Unset variables are left as the literal placeholder so
misconfiguration surfaces clearly in provider calls rather than
failing silently with an empty token.

The file is optional: missing file, parse errors, and per-entry
upsert failures all log a warning without aborting startup.
docker-compose.yml adds env_file (.env, required:false) so
deployment-specific variables are passed through automatically.
This commit is contained in:
jackson.jia
2026-05-22 23:15:12 +08:00
committed by lyingbug
parent e9be53e830
commit d439b3ae07
8 changed files with 475 additions and 113 deletions
+19
View File
@@ -427,6 +427,24 @@ type FebriText struct {
WithNoTag string `yaml:"with_no_tag" json:"with_no_tag"`
}
// resolvedConfigDir holds the directory of the loaded config file. Populated by
// LoadConfig and read by ConfigDir(); empty until LoadConfig has run.
var resolvedConfigDir string
// ConfigDir returns the directory containing the loaded config.yaml. Other
// startup code (e.g. builtin model loader) uses this to locate sibling config
// files like builtin_models.yaml without re-implementing viper search rules.
// Falls back to "./config" when LoadConfig has not been called yet.
func ConfigDir() string {
if resolvedConfigDir != "" {
return resolvedConfigDir
}
if f := viper.ConfigFileUsed(); f != "" {
return filepath.Dir(f)
}
return "./config"
}
// LoadConfig 从配置文件加载配置
func LoadConfig() (*Config, error) {
// 设置配置文件名和路径
@@ -478,6 +496,7 @@ func LoadConfig() (*Config, error) {
// 加载提示词模板(从目录或配置文件)
configDir := filepath.Dir(viper.ConfigFileUsed())
resolvedConfigDir = configDir
promptTemplates, err := loadPromptTemplates(configDir)
if err != nil {
fmt.Printf("Warning: failed to load prompt templates from directory: %v\n", err)