From 06a64c5e5a70d5f866c6dd9af493692756f0ae40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 13 Nov 2023 13:43:59 +0800 Subject: [PATCH] :bug: Fix a bug. --- handler/at_message.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/handler/at_message.go b/handler/at_message.go index 4ce8d68..ad8613c 100644 --- a/handler/at_message.go +++ b/handler/at_message.go @@ -2,10 +2,12 @@ package handler import ( "context" + "fmt" "github.com/sashabaranov/go-openai" "go-wechat/config" "go-wechat/entity" "go-wechat/utils" + "log" ) // handleAtMessage @@ -16,7 +18,11 @@ func handleAtMessage(m entity.Message) { return } // 默认使用AI回复 - client := openai.NewClient(config.Conf.Ai.ApiKey) + conf := openai.DefaultConfig(config.Conf.Ai.ApiKey) + if config.Conf.Ai.BaseUrl != "" { + conf.BaseURL = fmt.Sprintf("%s/v1", config.Conf.Ai.BaseUrl) + } + client := openai.NewClientWithConfig(conf) resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ @@ -31,6 +37,7 @@ func handleAtMessage(m entity.Message) { ) if err != nil { + log.Printf("OpenAI聊天发起失败: %v", err.Error()) utils.SendMessage(m.FromUser, m.GroupUser, "AI炸啦~", 0) return }