Skip to content

Commit fb32a5c

Browse files
authored
Merge branch 'FloatTech:master' into feature-rsshub-20250914
2 parents 13989e1 + 73eef96 commit fb32a5c

5 files changed

Lines changed: 53 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,7 @@ print("run[CQ:image,file="+j["img"]+"]")
16451645
- [x] 设置AI聊天触发概率10
16461646
- [x] 设置AI聊天温度80
16471647
- [x] 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI]
1648+
- [x] 设置AI聊天(不)使用Agent模式
16481649
- [x] 设置AI聊天(不)支持系统提示词
16491650
- [x] 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions
16501651
- [x] 设置AI聊天密钥xxx
@@ -1660,6 +1661,7 @@ print("run[CQ:image,file="+j["img"]+"]")
16601661
- [x] 查看AI聊天配置
16611662
- [x] 重置AI聊天
16621663
- [x] 群聊总结 [消息数目]|群聊总结 1000
1664+
- [x] /gpt [内容](使用大模型聊天)
16631665

16641666
</details>
16651667
<details>

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/FloatTech/sqlite v1.7.1
1313
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562
1414
github.com/FloatTech/zbpctrl v1.7.0
15-
github.com/FloatTech/zbputils v1.7.2-0.20250921072315-465a1f1d1fbb
15+
github.com/FloatTech/zbputils v1.7.2-0.20250922144137-bf2b9bb6a8d9
1616
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
1717
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
1818
github.com/Tnze/go-mc v1.20.2
@@ -24,6 +24,7 @@ require (
2424
github.com/fumiama/cron v1.3.0
2525
github.com/fumiama/deepinfra v0.0.0-20250920170049-e3d1b92cc3a1
2626
github.com/fumiama/go-base16384 v1.7.0
27+
github.com/fumiama/go-onebot-agent v0.0.0-20250922152742-c40bb3512d63
2728
github.com/fumiama/go-registry v0.2.7
2829
github.com/fumiama/gotracemoe v0.0.3
2930
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ
1717
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
1818
github.com/FloatTech/zbpctrl v1.7.0 h1:Hxo6EIhJo+pHjcQP9QgIJgluaT1pHH99zkk3njqTNMo=
1919
github.com/FloatTech/zbpctrl v1.7.0/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE=
20-
github.com/FloatTech/zbputils v1.7.2-0.20250921072315-465a1f1d1fbb h1:/3nfw+rPFvTNsEdj+QmslUL67QZeeO7Xkx2bxOnLtLo=
21-
github.com/FloatTech/zbputils v1.7.2-0.20250921072315-465a1f1d1fbb/go.mod h1:mkH3Tii83bsO7+gj5s3wLUWEIYY2+5G948aW4TtUxbg=
20+
github.com/FloatTech/zbputils v1.7.2-0.20250922144137-bf2b9bb6a8d9 h1:iR36inettls14aMOADNQ7PHNlGvgyDRRYp2dBgZCp8A=
21+
github.com/FloatTech/zbputils v1.7.2-0.20250922144137-bf2b9bb6a8d9/go.mod h1:L1Rvdf6JUXGRIdKaXVtBWa0iW481zccCjYdYeDSaMXs=
2222
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
2323
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
2424
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
6767
github.com/fumiama/deepinfra v0.0.0-20250920170049-e3d1b92cc3a1/go.mod h1:wW05PQSn8mo1mZIoa6LBUE+3xIBjkoONvnfPTV5ZOhY=
6868
github.com/fumiama/go-base16384 v1.7.0 h1:6fep7XPQWxRlh4Hu+KsdH+6+YdUp+w6CwRXtMWSsXCA=
6969
github.com/fumiama/go-base16384 v1.7.0/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
70+
github.com/fumiama/go-onebot-agent v0.0.0-20250922152742-c40bb3512d63 h1:ZdPMPIgZMH4HV4A/JIBb8G7UpLM4iUHWQ8qGjKnKiVI=
71+
github.com/fumiama/go-onebot-agent v0.0.0-20250922152742-c40bb3512d63/go.mod h1:wVMgFWkR3GpipL05FkokvrV/jWFIgoEWN1jzUGa0bWg=
7072
github.com/fumiama/go-registry v0.2.7 h1:tLEqgEpsiybQMqBv0dLHm5leia/z1DhajMupwnOHeNs=
7173
github.com/fumiama/go-registry v0.2.7/go.mod h1:m+wp5fF8dYgVoFkBPZl+vlK90loymaJE0JCtocVQLEs=
7274
github.com/fumiama/go-simple-protobuf v0.2.0 h1:ACyN1MAlu7pDR3EszWgzUeNP+IRsSHwH6V9JCJA5R5o=

plugin/aichat/cfg.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type config struct {
3030
NoReplyAT bool
3131
NoSystemP bool
3232
NoRecord bool
33+
NoAgent bool
3334
}
3435

3536
func newconfig() config {

plugin/aichat/main.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
package aichat
33

44
import (
5+
"encoding/json"
56
"errors"
67
"math/rand"
8+
"reflect"
79
"strconv"
810
"strings"
911
"time"
1012

1113
"github.com/fumiama/deepinfra"
1214
"github.com/fumiama/deepinfra/model"
15+
goba "github.com/fumiama/go-onebot-agent"
1316
"github.com/sirupsen/logrus"
1417
"github.com/tidwall/gjson"
1518

@@ -33,6 +36,7 @@ var (
3336
Help: "- 设置AI聊天触发概率10\n" +
3437
"- 设置AI聊天温度80\n" +
3538
"- 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI]\n" +
39+
"- 设置AI聊天(不)使用Agent模式\n" +
3640
"- 设置AI聊天(不)支持系统提示词\n" +
3741
"- 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions\n" +
3842
"- 设置AI聊天密钥xxx\n" +
@@ -142,6 +146,43 @@ func init() {
142146
return
143147
}
144148

149+
if !cfg.NoAgent {
150+
role := goba.PermRoleUser
151+
if zero.AdminPermission(ctx) {
152+
role = goba.PermRoleAdmin
153+
if zero.SuperUserPermission(ctx) {
154+
role = goba.PermRoleOwner
155+
}
156+
}
157+
reqs, err := chat.AgentOf(ctx.Event.SelfID).GetAction(x, mod, gid, role, false)
158+
if err != nil {
159+
logrus.Warnln("[aichat] agent err:", err, reqs)
160+
return
161+
}
162+
logrus.Infoln("[aichat] agent do:", reqs)
163+
for _, req := range reqs {
164+
if req.Action == "send_group_msg" {
165+
v, ok := req.Params["group_id"].(json.Number)
166+
if !ok {
167+
logrus.Warnln("[aichat] invalid group_id type", reflect.TypeOf(req.Params["group_id"]))
168+
continue
169+
}
170+
gid, err = v.Int64()
171+
if !ok {
172+
logrus.Warnln("[aichat] agent conv req gid err:", err)
173+
continue
174+
}
175+
if ctx.Event.GroupID != gid && !zero.SuperUserPermission(ctx) {
176+
logrus.Warnln("[aichat] refuse to send out of grp from", ctx.Event.GroupID, "to", gid)
177+
continue
178+
}
179+
}
180+
ctx.CallAction(req.Action, req.Params)
181+
process.SleepAbout1sTo2s()
182+
}
183+
return
184+
}
185+
145186
data, err := x.Request(chat.GetChatContext(mod, gid, cfg.SystemP, cfg.NoSystemP))
146187
if err != nil {
147188
logrus.Warnln("[aichat] post err:", err)
@@ -150,7 +191,7 @@ func init() {
150191

151192
txt := chat.Sanitize(strings.Trim(data, "\n  "))
152193
if len(txt) > 0 {
153-
chat.AddChatReply(gid, zero.BotConfig.NickName[0], txt)
194+
chat.AddChatReply(gid, txt)
154195
nick := zero.BotConfig.NickName[rand.Intn(len(zero.BotConfig.NickName))]
155196
txt = strings.ReplaceAll(txt, "{name}", ctx.CardOrNickName(ctx.Event.UserID))
156197
txt = strings.ReplaceAll(txt, "{me}", nick)
@@ -302,6 +343,8 @@ func init() {
302343
Handle(newextrasetbool(&cfg.NoReplyAT))
303344
en.OnRegex("^设置AI聊天(不)?支持系统提示词$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
304345
Handle(newextrasetbool(&cfg.NoSystemP))
346+
en.OnRegex("^设置AI聊天(不)?使用Agent模式$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
347+
Handle(newextrasetbool(&cfg.NoAgent))
305348
en.OnPrefix("设置AI聊天最大长度", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
306349
Handle(newextrasetuint(&cfg.MaxN))
307350
en.OnPrefix("设置AI聊天TopP", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).

0 commit comments

Comments
 (0)