- 新增config.yaml和config.go用于管理配置 - 重构chatmodel.go使用配置初始化模型 - 修改GenerateChatMessage和ChatStream函数签名添加context参数 - 更新main.go加载配置并初始化聊天模型 - 优化错误处理和日志输出
34 lines
551 B
Go
34 lines
551 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type OpenAIConfig struct {
|
|
BaseURL string `yaml:"base_url"`
|
|
Model string `yaml:"model"`
|
|
APIKey string `yaml:"api_key"`
|
|
Timeout time.Duration `yaml:"timeout"`
|
|
}
|
|
|
|
type Config struct {
|
|
OpenAI OpenAIConfig `yaml:"openai"`
|
|
}
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var config Config
|
|
if err := yaml.Unmarshal(data, &config); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &config, nil
|
|
}
|