Compare commits

..

6 Commits

Author SHA1 Message Date
李寻欢
8ff18c3626 Merge pull request '🎨 逻辑优化' (#17) from hotfix into main
Reviewed-on: https://gitee.ltd/lxh/go-wxhelper/pulls/17
2024-01-25 11:46:30 +08:00
李寻欢
6acb3b79ec 🎨 逻辑优化 2024-01-25 11:46:03 +08:00
李寻欢
f895d045a7 Merge pull request '🐛 修复AI开关未生效的BUG' (#16) from hotfix into main
Reviewed-on: https://gitee.ltd/lxh/go-wxhelper/pulls/16
2024-01-23 16:23:52 +08:00
李寻欢
eb2e292e8e 🐛 修复AI开关未生效的BUG 2024-01-23 16:23:07 +08:00
李寻欢
8f378e7fc9 Merge pull request '🔧 新增数据库配置模型' (#15) from hotfix into main
Reviewed-on: https://gitee.ltd/lxh/go-wxhelper/pulls/15
2024-01-22 08:32:00 +08:00
李寻欢
497e17ec62 🔧 新增数据库配置模型 2024-01-22 08:31:38 +08:00
3 changed files with 18 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ type Friend struct {
Pinyin string `json:"pinyin"` // 昵称拼音大写首字母 Pinyin string `json:"pinyin"` // 昵称拼音大写首字母
PinyinAll string `json:"pinyinAll"` // 昵称全拼 PinyinAll string `json:"pinyinAll"` // 昵称全拼
EnableAi bool `json:"enableAI" gorm:"type:tinyint(1) default 0 not null"` // 是否使用AI EnableAi bool `json:"enableAI" gorm:"type:tinyint(1) default 0 not null"` // 是否使用AI
AiModel string `json:"aiModel"` // AI模型
EnableChatRank bool `json:"enableChatRank" gorm:"type:tinyint(1) default 0 not null"` // 是否使用聊天排行 EnableChatRank bool `json:"enableChatRank" gorm:"type:tinyint(1) default 0 not null"` // 是否使用聊天排行
EnableWelcome bool `json:"enableWelcome" gorm:"type:tinyint(1) default 0 not null"` // 是否启用迎新 EnableWelcome bool `json:"enableWelcome" gorm:"type:tinyint(1) default 0 not null"` // 是否启用迎新
IsOk bool `json:"isOk" gorm:"type:tinyint(1) default 0 not null"` // 是否正常 IsOk bool `json:"isOk" gorm:"type:tinyint(1) default 0 not null"` // 是否正常

View File

@@ -28,9 +28,13 @@ func AI(m *plugin.MessageContext) {
} }
// 取出所有启用了AI的好友或群组 // 取出所有启用了AI的好友或群组
var count int64 var friendInfo entity.Friend
client.MySQL.Model(&entity.Friend{}).Where("enable_ai IS TRUE").Where("wxid = ?", m.FromUser).Count(&count) client.MySQL.Where("wxid = ?", m.FromUser).First(&friendInfo)
if count < 1 { if friendInfo.Wxid == "" {
return
}
// 判断有没有启用AI
if !friendInfo.EnableAi {
return return
} }
@@ -93,7 +97,9 @@ func AI(m *plugin.MessageContext) {
// 配置模型 // 配置模型
chatModel := openai.GPT3Dot5Turbo0613 chatModel := openai.GPT3Dot5Turbo0613
if config.Conf.Ai.Model != "" { if friendInfo.AiModel != "" {
chatModel = friendInfo.AiModel
} else if config.Conf.Ai.Model != "" {
chatModel = config.Conf.Ai.Model chatModel = config.Conf.Ai.Model
} }
@@ -117,6 +123,12 @@ func AI(m *plugin.MessageContext) {
return return
} }
// 返回消息为空
if resp.Choices[0].Message.Content == "" {
utils.SendMessage(m.FromUser, m.GroupUser, "AI似乎抽风了没有告诉我你需要的回答~", 0)
return
}
// 保存一下AI 返回的消息,消息 Id 使用传入 Id 的负数 // 保存一下AI 返回的消息,消息 Id 使用传入 Id 的负数
var replyMessage entity.Message var replyMessage entity.Message
replyMessage.MsgId = -m.MsgId replyMessage.MsgId = -m.MsgId

View File

@@ -13,6 +13,7 @@ type FriendItem struct {
PinyinAll string // 昵称全拼 PinyinAll string // 昵称全拼
Wxid string // 微信原始Id Wxid string // 微信原始Id
EnableAi bool // 是否使用AI EnableAi bool // 是否使用AI
AiModel string // AI模型
EnableChatRank bool // 是否使用聊天排行 EnableChatRank bool // 是否使用聊天排行
EnableWelcome bool // 是否使用迎新 EnableWelcome bool // 是否使用迎新
EnableCommand bool // 是否启用指令 EnableCommand bool // 是否启用指令