feat: 添加配置文件支持并重构聊天模块
- 新增config.yaml和config.go用于管理配置 - 重构chatmodel.go使用配置初始化模型 - 修改GenerateChatMessage和ChatStream函数签名添加context参数 - 更新main.go加载配置并初始化聊天模型 - 优化错误处理和日志输出
This commit is contained in:
@@ -14,9 +14,9 @@ var template = prompt.FromMessages(schema.FString,
|
||||
schema.MessagesPlaceholder("chat_history", true),
|
||||
schema.UserMessage("问题: {question}"))
|
||||
|
||||
func GenerateChatMessage(role, style, question string, history []*schema.Message) ([]*schema.Message, error) {
|
||||
func GenerateChatMessage(ctx context.Context, role, style, question string, history []*schema.Message) ([]*schema.Message, error) {
|
||||
// 在这里调用模板
|
||||
messages, err := template.Format(context.Background(), map[string]any{
|
||||
messages, err := template.Format(ctx, map[string]any{
|
||||
"role": role,
|
||||
"style": style,
|
||||
"question": question,
|
||||
|
||||
Reference in New Issue
Block a user