feat(aichat): add more options

This commit is contained in:
源文雨 2026-01-06 21:24:31 +08:00
parent caa66d6715
commit 5283e6de61
5 changed files with 51 additions and 19 deletions

View File

@ -1633,6 +1633,10 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 设置AI聊天最大长度4096
- [x] 设置AI聊天TopP 0.9
- [x] 设置AI聊天(不)以AI语音输出
- [x] 设置AI聊天Agent性格
- [x] 查看AI聊天Agent性格
- [x] 重置AI聊天Agent性格
- [x] 重置AI聊天Agent
- [x] 查看AI聊天配置
- [x] 重置AI聊天

6
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/FloatTech/sqlite v1.7.2
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d
github.com/FloatTech/zbpctrl v1.7.1
github.com/FloatTech/zbputils v1.7.2-0.20260104162610-89522e42ecca
github.com/FloatTech/zbputils v1.7.2-0.20260106131604-3ff237cdb792
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/RomiChan/websocket v1.4.3-0.20251002072000-d3eb41798438
github.com/Tnze/go-mc v1.20.2
@ -24,9 +24,10 @@ require (
github.com/fumiama/cron v1.3.0
github.com/fumiama/deepinfra v0.0.0-20251221163610-e98ee3ba437a
github.com/fumiama/go-base16384 v1.7.1
github.com/fumiama/go-onebot-agent v0.0.0-20260104164334-63ab0bc7f53a
github.com/fumiama/go-onebot-agent v0.0.0-20260106123931-a0c81601f2d7
github.com/fumiama/go-registry v0.2.7
github.com/fumiama/gotracemoe v0.0.3
github.com/fumiama/imgsz v0.0.4
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
github.com/fumiama/slowdo v0.0.0-20241001074058-27c4fe5259a4
github.com/fumiama/terasu v1.0.2
@ -65,7 +66,6 @@ require (
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
github.com/fumiama/go-simple-protobuf v0.2.0 // indirect
github.com/fumiama/gofastTEA v0.1.3 // indirect
github.com/fumiama/imgsz v0.0.4 // indirect
github.com/fumiama/orbyte v0.0.0-20251002065953-3bb358367eb5 // indirect
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect

8
go.sum
View File

@ -16,8 +16,8 @@ github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d h1:mUQ/c3wXKsUGa4Sg9
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/FloatTech/zbpctrl v1.7.1 h1:0yPEmCForhyMbnhTckmjDUFFDZgQp1RjO2bVF4ZVqOs=
github.com/FloatTech/zbpctrl v1.7.1/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE=
github.com/FloatTech/zbputils v1.7.2-0.20260104162610-89522e42ecca h1:E4FxbRVgDusR4JDif+vhT1DH2Tfnc3sQqOOxJQyfPho=
github.com/FloatTech/zbputils v1.7.2-0.20260104162610-89522e42ecca/go.mod h1:kpk47XoezsV4CjF5KV7EeirbySPaVb+gp4LBG8Xgb4k=
github.com/FloatTech/zbputils v1.7.2-0.20260106131604-3ff237cdb792 h1:LHJ75vp0gizrO1ko/2t8/98mPHD1bQSXkonn02VRB4A=
github.com/FloatTech/zbputils v1.7.2-0.20260106131604-3ff237cdb792/go.mod h1:TKnvn/rgLBlcizp8XtseduIkAw1Mq3cwpvT5GAG69fA=
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,8 +67,8 @@ github.com/fumiama/deepinfra v0.0.0-20251221163610-e98ee3ba437a h1:a0+2vaXajfxsN
github.com/fumiama/deepinfra v0.0.0-20251221163610-e98ee3ba437a/go.mod h1:uqsWK/GM9OvKV0pXZOQB63rWugBbiXInY8E1JoRKhkg=
github.com/fumiama/go-base16384 v1.7.1 h1:1P1x6FWRvd7PtbH4idDAGWAjKKcVxggxlROYKRXbw58=
github.com/fumiama/go-base16384 v1.7.1/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
github.com/fumiama/go-onebot-agent v0.0.0-20260104164334-63ab0bc7f53a h1:Wn57eAheMu/dgEzcKFYbfFtQmPL3HDrGAaNNwkzmcHc=
github.com/fumiama/go-onebot-agent v0.0.0-20260104164334-63ab0bc7f53a/go.mod h1:rTrS23rvTYuZcSngENJTvcBFTz1nGsImSv+bW7yfhqs=
github.com/fumiama/go-onebot-agent v0.0.0-20260106123931-a0c81601f2d7 h1:QYlLOAWxH3PU/vFiTmhI+TnsA4i+ahk+UxSbqBxkEOU=
github.com/fumiama/go-onebot-agent v0.0.0-20260106123931-a0c81601f2d7/go.mod h1:rTrS23rvTYuZcSngENJTvcBFTz1nGsImSv+bW7yfhqs=
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=

View File

@ -2,7 +2,6 @@
package aichat
import (
"encoding/json"
"math/rand"
"strings"
@ -122,15 +121,7 @@ func init() {
if req.Action == goba.SVM { // is a fake action
continue
}
resp := ctx.CallAction(req.Action, req.Params)
logrus.Infoln("[aichat] agent get resp:", reqs)
ag.AddResponse(gid, &goba.APIResponse{
Status: resp.Status,
Data: json.RawMessage(resp.Data.Raw),
Message: resp.Message,
Wording: resp.Wording,
RetCode: resp.RetCode,
})
_ = ctx.CallAction(req.Action, req.Params)
}
}
if hasresp {

View File

@ -29,18 +29,32 @@ var (
"- 查看AI聊天系统提示词\n" +
"- 重置AI聊天系统提示词\n" +
"- 设置AI聊天系统提示词xxx\n" +
"- 设置AI聊天Agent性格" +
"- 查看AI聊天Agent性格xxx" +
"- 重置AI聊天Agent性格\n" +
"- 设置AI聊天分隔符</think>(留空则清除)\n" +
"- 设置AI聊天(不)响应AT\n" +
"- 设置AI聊天最大长度4096\n" +
"- 设置AI聊天TopP 0.9\n" +
"- 设置AI聊天(不)以AI语音输出\n" +
"- 查看AI聊天配置\n" +
"- 重置AI聊天Agent\n" +
"- 重置AI聊天\n",
})
)
func init() {
en.UsePreHandler(func(ctx *zero.Ctx) bool {
en.UsePreHandler(chat.EnsureConfig, func(ctx *zero.Ctx) bool {
if !chat.IsAgentCharReady {
if chat.AC.AgentChar != "" {
chat.AgentChar = []byte(chat.AC.AgentChar)
}
chat.IsAgentCharReady = true
}
k := zero.StateKeyPrefixKeep + "aichatcfg_stor__"
if _, ok := ctx.State[k]; ok {
return true
}
gid := ctx.Event.GroupID
if gid == 0 {
gid = -ctx.Event.UserID
@ -50,7 +64,7 @@ func init() {
logrus.Warnln("ERROR: ", err)
return false
}
ctx.State[zero.StateKeyPrefixKeep+"aichatcfg_stor__"] = stor
ctx.State[k] = stor
return true
})
en.OnPrefix("设置AI聊天触发概率", zero.AdminPermission).SetBlock(true).
@ -83,9 +97,14 @@ func init() {
Handle(chat.NewExtraSetStr(&chat.AC.AgentModelName))
en.OnPrefix("设置AI聊天系统提示词", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
Handle(chat.NewExtraSetStr(&chat.AC.SystemP))
en.OnPrefix("设置AI聊天Agent性格", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
Handle(chat.NewExtraSetStr(&chat.AC.AgentChar))
en.OnFullMatch("查看AI聊天系统提示词", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text(chat.AC.SystemP))
})
en.OnFullMatch("查看AI聊天Agent性格", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text(chat.AC.AgentChar))
})
en.OnFullMatch("重置AI聊天系统提示词", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
if !ok {
@ -100,6 +119,20 @@ func init() {
}
ctx.SendChain(message.Text("成功"))
})
en.OnFullMatch("重置AI聊天Agent性格", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
if !ok {
ctx.SendChain(message.Text("ERROR: no such plugin"))
return
}
chat.AC.AgentChar = ""
err := c.SetExtra(&chat.AC)
if err != nil {
ctx.SendChain(message.Text("ERROR: set extra err: ", err))
return
}
ctx.SendChain(message.Text("成功, 请重置AI聊天Agent"))
})
en.OnPrefix("设置AI聊天分隔符", chat.EnsureConfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
Handle(chat.NewExtraSetStr(&chat.AC.Separator))
en.OnRegex("^设置AI聊天(不)?响应AT$", chat.EnsureConfig, zero.SuperUserPermission).SetBlock(true).
@ -137,6 +170,10 @@ func init() {
message.Text("【当前AI聊天全局配置】\n", &chat.AC),
)
})
en.OnFullMatch("重置AI聊天Agent", chat.EnsureConfig, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
chat.ResetAgents()
ctx.SendChain(message.Text("成功"))
})
en.OnFullMatch("重置AI聊天", chat.EnsureConfig, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
chat.ResetChat()
ctx.SendChain(message.Text("成功"))