1
0
forked from lxh/go-wxhelper

🐛 Fix a bug.

This commit is contained in:
李寻欢 2023-11-13 13:43:59 +08:00
parent 60bfa0e8a0
commit 06a64c5e5a

View File

@ -2,10 +2,12 @@ package handler
import ( import (
"context" "context"
"fmt"
"github.com/sashabaranov/go-openai" "github.com/sashabaranov/go-openai"
"go-wechat/config" "go-wechat/config"
"go-wechat/entity" "go-wechat/entity"
"go-wechat/utils" "go-wechat/utils"
"log"
) )
// handleAtMessage // handleAtMessage
@ -16,7 +18,11 @@ func handleAtMessage(m entity.Message) {
return return
} }
// 默认使用AI回复 // 默认使用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( resp, err := client.CreateChatCompletion(
context.Background(), context.Background(),
openai.ChatCompletionRequest{ openai.ChatCompletionRequest{
@ -31,6 +37,7 @@ func handleAtMessage(m entity.Message) {
) )
if err != nil { if err != nil {
log.Printf("OpenAI聊天发起失败: %v", err.Error())
utils.SendMessage(m.FromUser, m.GroupUser, "AI炸啦~", 0) utils.SendMessage(m.FromUser, m.GroupUser, "AI炸啦~", 0)
return return
} }