diff --git a/README.md b/README.md index 322fef20..ddaf845a 100644 --- a/README.md +++ b/README.md @@ -1645,6 +1645,7 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 设置AI聊天触发概率10 - [x] 设置AI聊天温度80 - [x] 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI] + - [x] 设置AI聊天(不)使用Agent模式 - [x] 设置AI聊天(不)支持系统提示词 - [x] 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions - [x] 设置AI聊天密钥xxx @@ -1660,6 +1661,7 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 查看AI聊天配置 - [x] 重置AI聊天 - [x] 群聊总结 [消息数目]|群聊总结 1000 + - [x] /gpt [内容](使用大模型聊天)
diff --git a/go.mod b/go.mod index 0d58b59c..9428c062 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/FloatTech/sqlite v1.7.1 github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 github.com/FloatTech/zbpctrl v1.7.0 - github.com/FloatTech/zbputils v1.7.2-0.20250921072315-465a1f1d1fbb + github.com/FloatTech/zbputils v1.7.2-0.20250922144137-bf2b9bb6a8d9 github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 github.com/Tnze/go-mc v1.20.2 @@ -24,6 +24,7 @@ require ( github.com/fumiama/cron v1.3.0 github.com/fumiama/deepinfra v0.0.0-20250920170049-e3d1b92cc3a1 github.com/fumiama/go-base16384 v1.7.0 + github.com/fumiama/go-onebot-agent v0.0.0-20250922152742-c40bb3512d63 github.com/fumiama/go-registry v0.2.7 github.com/fumiama/gotracemoe v0.0.3 github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565 diff --git a/go.sum b/go.sum index da4d583f..b0b8fce9 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= github.com/FloatTech/zbpctrl v1.7.0 h1:Hxo6EIhJo+pHjcQP9QgIJgluaT1pHH99zkk3njqTNMo= github.com/FloatTech/zbpctrl v1.7.0/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE= -github.com/FloatTech/zbputils v1.7.2-0.20250921072315-465a1f1d1fbb h1:/3nfw+rPFvTNsEdj+QmslUL67QZeeO7Xkx2bxOnLtLo= -github.com/FloatTech/zbputils v1.7.2-0.20250921072315-465a1f1d1fbb/go.mod h1:mkH3Tii83bsO7+gj5s3wLUWEIYY2+5G948aW4TtUxbg= +github.com/FloatTech/zbputils v1.7.2-0.20250922144137-bf2b9bb6a8d9 h1:iR36inettls14aMOADNQ7PHNlGvgyDRRYp2dBgZCp8A= +github.com/FloatTech/zbputils v1.7.2-0.20250922144137-bf2b9bb6a8d9/go.mod h1:L1Rvdf6JUXGRIdKaXVtBWa0iW481zccCjYdYeDSaMXs= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U= github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI= @@ -67,6 +67,8 @@ github.com/fumiama/deepinfra v0.0.0-20250920170049-e3d1b92cc3a1 h1:6PglFpNVm3Dal github.com/fumiama/deepinfra v0.0.0-20250920170049-e3d1b92cc3a1/go.mod h1:wW05PQSn8mo1mZIoa6LBUE+3xIBjkoONvnfPTV5ZOhY= github.com/fumiama/go-base16384 v1.7.0 h1:6fep7XPQWxRlh4Hu+KsdH+6+YdUp+w6CwRXtMWSsXCA= github.com/fumiama/go-base16384 v1.7.0/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM= +github.com/fumiama/go-onebot-agent v0.0.0-20250922152742-c40bb3512d63 h1:ZdPMPIgZMH4HV4A/JIBb8G7UpLM4iUHWQ8qGjKnKiVI= +github.com/fumiama/go-onebot-agent v0.0.0-20250922152742-c40bb3512d63/go.mod h1:wVMgFWkR3GpipL05FkokvrV/jWFIgoEWN1jzUGa0bWg= github.com/fumiama/go-registry v0.2.7 h1:tLEqgEpsiybQMqBv0dLHm5leia/z1DhajMupwnOHeNs= github.com/fumiama/go-registry v0.2.7/go.mod h1:m+wp5fF8dYgVoFkBPZl+vlK90loymaJE0JCtocVQLEs= github.com/fumiama/go-simple-protobuf v0.2.0 h1:ACyN1MAlu7pDR3EszWgzUeNP+IRsSHwH6V9JCJA5R5o= diff --git a/plugin/aichat/cfg.go b/plugin/aichat/cfg.go index f9287532..6299e169 100644 --- a/plugin/aichat/cfg.go +++ b/plugin/aichat/cfg.go @@ -30,6 +30,7 @@ type config struct { NoReplyAT bool NoSystemP bool NoRecord bool + NoAgent bool } func newconfig() config { diff --git a/plugin/aichat/main.go b/plugin/aichat/main.go index 6b34a6be..4292761b 100644 --- a/plugin/aichat/main.go +++ b/plugin/aichat/main.go @@ -2,14 +2,17 @@ package aichat import ( + "encoding/json" "errors" "math/rand" + "reflect" "strconv" "strings" "time" "github.com/fumiama/deepinfra" "github.com/fumiama/deepinfra/model" + goba "github.com/fumiama/go-onebot-agent" "github.com/sirupsen/logrus" "github.com/tidwall/gjson" @@ -33,6 +36,7 @@ var ( Help: "- 设置AI聊天触发概率10\n" + "- 设置AI聊天温度80\n" + "- 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI]\n" + + "- 设置AI聊天(不)使用Agent模式\n" + "- 设置AI聊天(不)支持系统提示词\n" + "- 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions\n" + "- 设置AI聊天密钥xxx\n" + @@ -142,6 +146,43 @@ func init() { return } + if !cfg.NoAgent { + role := goba.PermRoleUser + if zero.AdminPermission(ctx) { + role = goba.PermRoleAdmin + if zero.SuperUserPermission(ctx) { + role = goba.PermRoleOwner + } + } + reqs, err := chat.AgentOf(ctx.Event.SelfID).GetAction(x, mod, gid, role, false) + if err != nil { + logrus.Warnln("[aichat] agent err:", err, reqs) + return + } + logrus.Infoln("[aichat] agent do:", reqs) + for _, req := range reqs { + if req.Action == "send_group_msg" { + v, ok := req.Params["group_id"].(json.Number) + if !ok { + logrus.Warnln("[aichat] invalid group_id type", reflect.TypeOf(req.Params["group_id"])) + continue + } + gid, err = v.Int64() + if !ok { + logrus.Warnln("[aichat] agent conv req gid err:", err) + continue + } + if ctx.Event.GroupID != gid && !zero.SuperUserPermission(ctx) { + logrus.Warnln("[aichat] refuse to send out of grp from", ctx.Event.GroupID, "to", gid) + continue + } + } + ctx.CallAction(req.Action, req.Params) + process.SleepAbout1sTo2s() + } + return + } + data, err := x.Request(chat.GetChatContext(mod, gid, cfg.SystemP, cfg.NoSystemP)) if err != nil { logrus.Warnln("[aichat] post err:", err) @@ -150,7 +191,7 @@ func init() { txt := chat.Sanitize(strings.Trim(data, "\n  ")) if len(txt) > 0 { - chat.AddChatReply(gid, zero.BotConfig.NickName[0], txt) + chat.AddChatReply(gid, txt) nick := zero.BotConfig.NickName[rand.Intn(len(zero.BotConfig.NickName))] txt = strings.ReplaceAll(txt, "{name}", ctx.CardOrNickName(ctx.Event.UserID)) txt = strings.ReplaceAll(txt, "{me}", nick) @@ -302,6 +343,8 @@ func init() { Handle(newextrasetbool(&cfg.NoReplyAT)) en.OnRegex("^设置AI聊天(不)?支持系统提示词$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). Handle(newextrasetbool(&cfg.NoSystemP)) + en.OnRegex("^设置AI聊天(不)?使用Agent模式$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). + Handle(newextrasetbool(&cfg.NoAgent)) en.OnPrefix("设置AI聊天最大长度", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). Handle(newextrasetuint(&cfg.MaxN)) en.OnPrefix("设置AI聊天TopP", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).