feat: 添加配置文件支持并重构聊天模块
- 新增config.yaml和config.go用于管理配置 - 重构chatmodel.go使用配置初始化模型 - 修改GenerateChatMessage和ChatStream函数签名添加context参数 - 更新main.go加载配置并初始化聊天模型 - 优化错误处理和日志输出
This commit is contained in:
@@ -2,23 +2,21 @@ package chat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"enio_meowrain/config"
|
||||
|
||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
||||
)
|
||||
|
||||
func CreateChatModel() (*openai.ChatModel, context.Context) {
|
||||
ctx := context.Background()
|
||||
timeout := 30 * time.Second
|
||||
func CreateChatModel(ctx context.Context, cfg *config.Config) (*openai.ChatModel, error) {
|
||||
chatModel, err := openai.NewChatModel(ctx, &openai.ChatModelConfig{
|
||||
BaseURL: "https://api-proxy.meowrain.cn/ai/v1",
|
||||
Model: "deepseek-v3.2",
|
||||
APIKey: "meowrain",
|
||||
Timeout: timeout,
|
||||
BaseURL: cfg.OpenAI.BaseURL,
|
||||
Model: cfg.OpenAI.Model,
|
||||
APIKey: cfg.OpenAI.APIKey,
|
||||
Timeout: cfg.OpenAI.Timeout,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
return chatModel, ctx
|
||||
return chatModel, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user