gpt唤醒词配置
This commit is contained in:
parent
cf4ac6d173
commit
2d43dd8d3b
@ -2,4 +2,6 @@
|
||||
"api_key": "", # chatgpt api key
|
||||
"auto_pass": true, # 是否自动通过好友申请
|
||||
"bing_chat_url": "" # New Bing 聊天接口
|
||||
"bing_chat_wake_word": "#bing", # new Bing唤醒词
|
||||
"gpt_chat_wake_word": "#gpt" # ChatGPT唤醒词
|
||||
}
|
||||
|
||||
@ -13,9 +13,11 @@ type Configuration struct {
|
||||
ApiKey string `json:"api_key"`
|
||||
// 自动通过好友
|
||||
AutoPass bool `json:"auto_pass"`
|
||||
|
||||
// bing 聊天接口
|
||||
BingChatUrl string `json:"bing_chat_url"`
|
||||
// 机器人唤醒词
|
||||
BingChatWakeWord string `json:"bing_chat_wake_word"`
|
||||
GptChatWakeWord string `json:"gpt_chat_wake_word"`
|
||||
}
|
||||
|
||||
var config *Configuration
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/bujnlc8/wechatbot/config"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
@ -16,10 +17,12 @@ type GroupMessageHandler struct {
|
||||
|
||||
// handle 处理消息
|
||||
func (g *GroupMessageHandler) handle(msg *openwechat.Message) error {
|
||||
bingWakeWord := config.LoadConfig().BingChatWakeWord
|
||||
gptWakeWord := config.LoadConfig().GptChatWakeWord
|
||||
if msg.IsText() {
|
||||
return g.ReplyText(msg)
|
||||
} else {
|
||||
if strings.Contains(msg.Content, "@GPTBot") || strings.Contains(msg.Content, "@bing") {
|
||||
if strings.Contains(msg.Content, gptWakeWord) || strings.Contains(msg.Content, bingWakeWord) {
|
||||
msg.ReplyText("目前我只支持文字哦~")
|
||||
}
|
||||
}
|
||||
@ -40,15 +43,18 @@ func (g *GroupMessageHandler) ReplyText(msg *openwechat.Message) error {
|
||||
group := openwechat.Group{User: sender}
|
||||
log.Printf("Received Group %v Text Msg : %v", group.NickName, msg.Content)
|
||||
|
||||
bingWakeWord := config.LoadConfig().BingChatWakeWord
|
||||
gptWakeWord := config.LoadConfig().GptChatWakeWord
|
||||
|
||||
// @GPTBot 或者 @bing的消息才处理
|
||||
if !(strings.Contains(msg.Content, "@GPTBot") || strings.Contains(msg.Content, "@bing")) {
|
||||
if !(strings.Contains(msg.Content, gptWakeWord) || strings.Contains(msg.Content, bingWakeWord)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
requestText := strings.TrimSpace(strings.ReplaceAll(msg.Content, "@GPTBot", ""))
|
||||
requestText := strings.TrimSpace(strings.ReplaceAll(msg.Content, gptWakeWord, ""))
|
||||
var reply = ""
|
||||
if strings.Contains(msg.Content, "@bing") {
|
||||
requestText = strings.TrimSpace(strings.ReplaceAll(msg.Content, "@bing", ""))
|
||||
if strings.Contains(msg.Content, bingWakeWord) {
|
||||
requestText = strings.TrimSpace(strings.ReplaceAll(msg.Content, bingWakeWord, ""))
|
||||
reply, err = gpt.BingSearch(requestText, group.UserName)
|
||||
if reply != "" && strings.HasPrefix(reply, "[") {
|
||||
reply = "\n" + reply
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/bujnlc8/wechatbot/config"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
@ -43,12 +44,18 @@ func (g *UserMessageHandler) ReplyText(msg *openwechat.Message) error {
|
||||
requestText := strings.TrimSpace(msg.Content)
|
||||
requestText = strings.Trim(msg.Content, "\n")
|
||||
|
||||
bingWakeWord := config.LoadConfig().BingChatWakeWord
|
||||
gptWakeWord := config.LoadConfig().GptChatWakeWord
|
||||
|
||||
var reply = ""
|
||||
if strings.Contains(msg.Content, "@bing") {
|
||||
requestText = strings.TrimSpace(strings.ReplaceAll(msg.Content, "@bing", ""))
|
||||
if strings.Contains(msg.Content, bingWakeWord) {
|
||||
requestText = strings.TrimSpace(strings.ReplaceAll(msg.Content, bingWakeWord, ""))
|
||||
reply, err = gpt.BingSearch(requestText, sender.UserName)
|
||||
} else {
|
||||
} else if strings.Contains(msg.Content, gptWakeWord) {
|
||||
requestText = strings.TrimSpace(strings.ReplaceAll(msg.Content, gptWakeWord, ""))
|
||||
reply, err = gpt.Completions(requestText, sender.UserName)
|
||||
} else {
|
||||
//可以考虑对接其他机器人恢复信息
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("gpt request error: %v \n", err)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user