Merge branch 'FloatTech:master' into feature-rsshub-20250914

This commit is contained in:
himawari 2025-09-23 08:06:00 +08:00 committed by GitHub
commit fb32a5c513
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 53 additions and 4 deletions

View File

@ -1645,6 +1645,7 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 设置AI聊天触发概率10 - [x] 设置AI聊天触发概率10
- [x] 设置AI聊天温度80 - [x] 设置AI聊天温度80
- [x] 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI] - [x] 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI]
- [x] 设置AI聊天(不)使用Agent模式
- [x] 设置AI聊天(不)支持系统提示词 - [x] 设置AI聊天(不)支持系统提示词
- [x] 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions - [x] 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions
- [x] 设置AI聊天密钥xxx - [x] 设置AI聊天密钥xxx
@ -1660,6 +1661,7 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 查看AI聊天配置 - [x] 查看AI聊天配置
- [x] 重置AI聊天 - [x] 重置AI聊天
- [x] 群聊总结 [消息数目]|群聊总结 1000 - [x] 群聊总结 [消息数目]|群聊总结 1000
- [x] /gpt [内容](使用大模型聊天)
</details> </details>
<details> <details>

3
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/FloatTech/sqlite v1.7.1 github.com/FloatTech/sqlite v1.7.1
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562
github.com/FloatTech/zbpctrl v1.7.0 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/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
github.com/Tnze/go-mc v1.20.2 github.com/Tnze/go-mc v1.20.2
@ -24,6 +24,7 @@ require (
github.com/fumiama/cron v1.3.0 github.com/fumiama/cron v1.3.0
github.com/fumiama/deepinfra v0.0.0-20250920170049-e3d1b92cc3a1 github.com/fumiama/deepinfra v0.0.0-20250920170049-e3d1b92cc3a1
github.com/fumiama/go-base16384 v1.7.0 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/go-registry v0.2.7
github.com/fumiama/gotracemoe v0.0.3 github.com/fumiama/gotracemoe v0.0.3
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565 github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565

6
go.sum
View File

@ -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/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 h1:Hxo6EIhJo+pHjcQP9QgIJgluaT1pHH99zkk3njqTNMo=
github.com/FloatTech/zbpctrl v1.7.0/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE= 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.20250922144137-bf2b9bb6a8d9 h1:iR36inettls14aMOADNQ7PHNlGvgyDRRYp2dBgZCp8A=
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/go.mod h1:L1Rvdf6JUXGRIdKaXVtBWa0iW481zccCjYdYeDSaMXs=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= 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 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI= 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/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 h1:6fep7XPQWxRlh4Hu+KsdH+6+YdUp+w6CwRXtMWSsXCA=
github.com/fumiama/go-base16384 v1.7.0/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM= 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 h1:tLEqgEpsiybQMqBv0dLHm5leia/z1DhajMupwnOHeNs=
github.com/fumiama/go-registry v0.2.7/go.mod h1:m+wp5fF8dYgVoFkBPZl+vlK90loymaJE0JCtocVQLEs= 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= github.com/fumiama/go-simple-protobuf v0.2.0 h1:ACyN1MAlu7pDR3EszWgzUeNP+IRsSHwH6V9JCJA5R5o=

View File

@ -30,6 +30,7 @@ type config struct {
NoReplyAT bool NoReplyAT bool
NoSystemP bool NoSystemP bool
NoRecord bool NoRecord bool
NoAgent bool
} }
func newconfig() config { func newconfig() config {

View File

@ -2,14 +2,17 @@
package aichat package aichat
import ( import (
"encoding/json"
"errors" "errors"
"math/rand" "math/rand"
"reflect"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/fumiama/deepinfra" "github.com/fumiama/deepinfra"
"github.com/fumiama/deepinfra/model" "github.com/fumiama/deepinfra/model"
goba "github.com/fumiama/go-onebot-agent"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
@ -33,6 +36,7 @@ var (
Help: "- 设置AI聊天触发概率10\n" + Help: "- 设置AI聊天触发概率10\n" +
"- 设置AI聊天温度80\n" + "- 设置AI聊天温度80\n" +
"- 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI]\n" + "- 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI]\n" +
"- 设置AI聊天(不)使用Agent模式\n" +
"- 设置AI聊天(不)支持系统提示词\n" + "- 设置AI聊天(不)支持系统提示词\n" +
"- 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions\n" + "- 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions\n" +
"- 设置AI聊天密钥xxx\n" + "- 设置AI聊天密钥xxx\n" +
@ -142,6 +146,43 @@ func init() {
return 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)) data, err := x.Request(chat.GetChatContext(mod, gid, cfg.SystemP, cfg.NoSystemP))
if err != nil { if err != nil {
logrus.Warnln("[aichat] post err:", err) logrus.Warnln("[aichat] post err:", err)
@ -150,7 +191,7 @@ func init() {
txt := chat.Sanitize(strings.Trim(data, "\n  ")) txt := chat.Sanitize(strings.Trim(data, "\n  "))
if len(txt) > 0 { 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))] nick := zero.BotConfig.NickName[rand.Intn(len(zero.BotConfig.NickName))]
txt = strings.ReplaceAll(txt, "{name}", ctx.CardOrNickName(ctx.Event.UserID)) txt = strings.ReplaceAll(txt, "{name}", ctx.CardOrNickName(ctx.Event.UserID))
txt = strings.ReplaceAll(txt, "{me}", nick) txt = strings.ReplaceAll(txt, "{me}", nick)
@ -302,6 +343,8 @@ func init() {
Handle(newextrasetbool(&cfg.NoReplyAT)) Handle(newextrasetbool(&cfg.NoReplyAT))
en.OnRegex("^设置AI聊天(不)?支持系统提示词$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). en.OnRegex("^设置AI聊天(不)?支持系统提示词$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
Handle(newextrasetbool(&cfg.NoSystemP)) 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). en.OnPrefix("设置AI聊天最大长度", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
Handle(newextrasetuint(&cfg.MaxN)) Handle(newextrasetuint(&cfg.MaxN))
en.OnPrefix("设置AI聊天TopP", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). en.OnPrefix("设置AI聊天TopP", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).