Skip to content

Commit 5283e6d

Browse files
committed
feat(aichat): add more options
1 parent caa66d6 commit 5283e6d

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,10 @@ print("run[CQ:image,file="+j["img"]+"]")
16331633
- [x] 设置AI聊天最大长度4096
16341634
- [x] 设置AI聊天TopP 0.9
16351635
- [x] 设置AI聊天(不)以AI语音输出
1636+
- [x] 设置AI聊天Agent性格
1637+
- [x] 查看AI聊天Agent性格
1638+
- [x] 重置AI聊天Agent性格
1639+
- [x] 重置AI聊天Agent
16361640
- [x] 查看AI聊天配置
16371641
- [x] 重置AI聊天
16381642

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/FloatTech/sqlite v1.7.2
1313
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d
1414
github.com/FloatTech/zbpctrl v1.7.1
15-
github.com/FloatTech/zbputils v1.7.2-0.20260104162610-89522e42ecca
15+
github.com/FloatTech/zbputils v1.7.2-0.20260106131604-3ff237cdb792
1616
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
1717
github.com/RomiChan/websocket v1.4.3-0.20251002072000-d3eb41798438
1818
github.com/Tnze/go-mc v1.20.2
@@ -24,9 +24,10 @@ require (
2424
github.com/fumiama/cron v1.3.0
2525
github.com/fumiama/deepinfra v0.0.0-20251221163610-e98ee3ba437a
2626
github.com/fumiama/go-base16384 v1.7.1
27-
github.com/fumiama/go-onebot-agent v0.0.0-20260104164334-63ab0bc7f53a
27+
github.com/fumiama/go-onebot-agent v0.0.0-20260106123931-a0c81601f2d7
2828
github.com/fumiama/go-registry v0.2.7
2929
github.com/fumiama/gotracemoe v0.0.3
30+
github.com/fumiama/imgsz v0.0.4
3031
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
3132
github.com/fumiama/slowdo v0.0.0-20241001074058-27c4fe5259a4
3233
github.com/fumiama/terasu v1.0.2
@@ -65,7 +66,6 @@ require (
6566
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
6667
github.com/fumiama/go-simple-protobuf v0.2.0 // indirect
6768
github.com/fumiama/gofastTEA v0.1.3 // indirect
68-
github.com/fumiama/imgsz v0.0.4 // indirect
6969
github.com/fumiama/orbyte v0.0.0-20251002065953-3bb358367eb5 // indirect
7070
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
7171
github.com/go-ole/go-ole v1.2.6 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d h1:mUQ/c3wXKsUGa4Sg9
1616
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
1717
github.com/FloatTech/zbpctrl v1.7.1 h1:0yPEmCForhyMbnhTckmjDUFFDZgQp1RjO2bVF4ZVqOs=
1818
github.com/FloatTech/zbpctrl v1.7.1/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE=
19-
github.com/FloatTech/zbputils v1.7.2-0.20260104162610-89522e42ecca h1:E4FxbRVgDusR4JDif+vhT1DH2Tfnc3sQqOOxJQyfPho=
20-
github.com/FloatTech/zbputils v1.7.2-0.20260104162610-89522e42ecca/go.mod h1:kpk47XoezsV4CjF5KV7EeirbySPaVb+gp4LBG8Xgb4k=
19+
github.com/FloatTech/zbputils v1.7.2-0.20260106131604-3ff237cdb792 h1:LHJ75vp0gizrO1ko/2t8/98mPHD1bQSXkonn02VRB4A=
20+
github.com/FloatTech/zbputils v1.7.2-0.20260106131604-3ff237cdb792/go.mod h1:TKnvn/rgLBlcizp8XtseduIkAw1Mq3cwpvT5GAG69fA=
2121
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
2222
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
2323
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
@@ -67,8 +67,8 @@ github.com/fumiama/deepinfra v0.0.0-20251221163610-e98ee3ba437a h1:a0+2vaXajfxsN
6767
github.com/fumiama/deepinfra v0.0.0-20251221163610-e98ee3ba437a/go.mod h1:uqsWK/GM9OvKV0pXZOQB63rWugBbiXInY8E1JoRKhkg=
6868
github.com/fumiama/go-base16384 v1.7.1 h1:1P1x6FWRvd7PtbH4idDAGWAjKKcVxggxlROYKRXbw58=
6969
github.com/fumiama/go-base16384 v1.7.1/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
70-
github.com/fumiama/go-onebot-agent v0.0.0-20260104164334-63ab0bc7f53a h1:Wn57eAheMu/dgEzcKFYbfFtQmPL3HDrGAaNNwkzmcHc=
71-
github.com/fumiama/go-onebot-agent v0.0.0-20260104164334-63ab0bc7f53a/go.mod h1:rTrS23rvTYuZcSngENJTvcBFTz1nGsImSv+bW7yfhqs=
70+
github.com/fumiama/go-onebot-agent v0.0.0-20260106123931-a0c81601f2d7 h1:QYlLOAWxH3PU/vFiTmhI+TnsA4i+ahk+UxSbqBxkEOU=
71+
github.com/fumiama/go-onebot-agent v0.0.0-20260106123931-a0c81601f2d7/go.mod h1:rTrS23rvTYuZcSngENJTvcBFTz1nGsImSv+bW7yfhqs=
7272
github.com/fumiama/go-registry v0.2.7 h1:tLEqgEpsiybQMqBv0dLHm5leia/z1DhajMupwnOHeNs=
7373
github.com/fumiama/go-registry v0.2.7/go.mod h1:m+wp5fF8dYgVoFkBPZl+vlK90loymaJE0JCtocVQLEs=
7474
github.com/fumiama/go-simple-protobuf v0.2.0 h1:ACyN1MAlu7pDR3EszWgzUeNP+IRsSHwH6V9JCJA5R5o=

plugin/aichat/main.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package aichat
33

44
import (
5-
"encoding/json"
65
"math/rand"
76
"strings"
87

@@ -122,15 +121,7 @@ func init() {
122121
if req.Action == goba.SVM { // is a fake action
123122
continue
124123
}
125-
resp := ctx.CallAction(req.Action, req.Params)
126-
logrus.Infoln("[aichat] agent get resp:", reqs)
127-
ag.AddResponse(gid, &goba.APIResponse{
128-
Status: resp.Status,
129-
Data: json.RawMessage(resp.Data.Raw),
130-
Message: resp.Message,
131-
Wording: resp.Wording,
132-
RetCode: resp.RetCode,
133-
})
124+
_ = ctx.CallAction(req.Action, req.Params)
134125
}
135126
}
136127
if hasresp {

plugin/aichatcfg/main.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,32 @@ var (
2929
"- 查看AI聊天系统提示词\n" +
3030
"- 重置AI聊天系统提示词\n" +
3131
"- 设置AI聊天系统提示词xxx\n" +
32+
"- 设置AI聊天Agent性格" +
33+
"- 查看AI聊天Agent性格xxx" +
34+
"- 重置AI聊天Agent性格\n" +
3235
"- 设置AI聊天分隔符</think>(留空则清除)\n" +
3336
"- 设置AI聊天(不)响应AT\n" +
3437
"- 设置AI聊天最大长度4096\n" +
3538
"- 设置AI聊天TopP 0.9\n" +
3639
"- 设置AI聊天(不)以AI语音输出\n" +
3740
"- 查看AI聊天配置\n" +
41+
"- 重置AI聊天Agent\n" +
3842
"- 重置AI聊天\n",
3943
})
4044
)
4145

4246
func init() {
43-
en.UsePreHandler(func(ctx *zero.Ctx) bool {
47+
en.UsePreHandler(chat.EnsureConfig, func(ctx *zero.Ctx) bool {
48+
if !chat.IsAgentCharReady {
49+
if chat.AC.AgentChar != "" {
50+
chat.AgentChar = []byte(chat.AC.AgentChar)
51+
}
52+
chat.IsAgentCharReady = true
53+
}
54+
k := zero.StateKeyPrefixKeep + "aichatcfg_stor__"
55+
if _, ok := ctx.State[k]; ok {
56+
return true
57+
}
4458
gid := ctx.Event.GroupID
4559
if gid == 0 {
4660
gid = -ctx.Event.UserID
@@ -50,7 +64,7 @@ func init() {
5064
logrus.Warnln("ERROR: ", err)
5165
return false
5266
}
53-
ctx.State[zero.StateKeyPrefixKeep+"aichatcfg_stor__"] = stor
67+
ctx.State[k] = stor
5468
return true
5569
})
5670
en.OnPrefix("设置AI聊天触发概率", zero.AdminPermission).SetBlock(true).
@@ -83,9 +97,14 @@ func init() {
8397
Handle(chat.NewExtraSetStr(&chat.AC.AgentModelName))
8498
en.OnPrefix("设置AI聊天系统提示词", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
8599
Handle(chat.NewExtraSetStr(&chat.AC.SystemP))
100+
en.OnPrefix("设置AI聊天Agent性格", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
101+
Handle(chat.NewExtraSetStr(&chat.AC.AgentChar))
86102
en.OnFullMatch("查看AI聊天系统提示词", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
87103
ctx.SendChain(message.Text(chat.AC.SystemP))
88104
})
105+
en.OnFullMatch("查看AI聊天Agent性格", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
106+
ctx.SendChain(message.Text(chat.AC.AgentChar))
107+
})
89108
en.OnFullMatch("重置AI聊天系统提示词", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
90109
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
91110
if !ok {
@@ -100,6 +119,20 @@ func init() {
100119
}
101120
ctx.SendChain(message.Text("成功"))
102121
})
122+
en.OnFullMatch("重置AI聊天Agent性格", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
123+
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
124+
if !ok {
125+
ctx.SendChain(message.Text("ERROR: no such plugin"))
126+
return
127+
}
128+
chat.AC.AgentChar = ""
129+
err := c.SetExtra(&chat.AC)
130+
if err != nil {
131+
ctx.SendChain(message.Text("ERROR: set extra err: ", err))
132+
return
133+
}
134+
ctx.SendChain(message.Text("成功, 请重置AI聊天Agent"))
135+
})
103136
en.OnPrefix("设置AI聊天分隔符", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
104137
Handle(chat.NewExtraSetStr(&chat.AC.Separator))
105138
en.OnRegex("^设置AI聊天(不)?响应AT$", chat.EnsureConfig, zero.SuperUserPermission).SetBlock(true).
@@ -137,6 +170,10 @@ func init() {
137170
message.Text("【当前AI聊天全局配置】\n", &chat.AC),
138171
)
139172
})
173+
en.OnFullMatch("重置AI聊天Agent", chat.EnsureConfig, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
174+
chat.ResetAgents()
175+
ctx.SendChain(message.Text("成功"))
176+
})
140177
en.OnFullMatch("重置AI聊天", chat.EnsureConfig, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
141178
chat.ResetChat()
142179
ctx.SendChain(message.Text("成功"))

0 commit comments

Comments
 (0)