diff --git a/README.md b/README.md index 54f59afd..f48d83ef 100644 --- a/README.md +++ b/README.md @@ -1588,6 +1588,8 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 设置AI聊天系统提示词xxx - [x] 设置AI聊天分隔符``(留空则清除) - [x] 设置AI聊天(不)响应AT + - [x] 设置AI聊天最大长度4096 + - [x] 设置AI聊天TopP 0.9
diff --git a/go.mod b/go.mod index 22f92eb0..f9cde00b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/Baidu-AIP/golang-sdk v1.1.1 - github.com/FloatTech/AnimeAPI v1.7.1-0.20250423082452-e16339a3962c + github.com/FloatTech/AnimeAPI v1.7.1-0.20250530055006-50f5c7587c5b github.com/FloatTech/floatbox v0.0.0-20250513111443-adba80e84e80 github.com/FloatTech/gg v1.1.3 github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef @@ -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.20250330125231-d8be1c9d3b9c + github.com/FloatTech/zbputils v1.7.2-0.20250601064658-421e71926b83 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 diff --git a/go.sum b/go.sum index 6b04ccf9..34666119 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/Baidu-AIP/golang-sdk v1.1.1 h1:RQsAmgDSAkiq22I6n7XJ2t3afgzFeqjY46FGhvrx4cw= github.com/Baidu-AIP/golang-sdk v1.1.1/go.mod h1:bXnGw7xPeKt8aF7UCELKrV6UZ/46spItONK1RQBQj1Y= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= -github.com/FloatTech/AnimeAPI v1.7.1-0.20250423082452-e16339a3962c h1:bEe8VP2aHLR2NHk1BsBQFtP0XE3cxquvr0tW0CkKcDk= -github.com/FloatTech/AnimeAPI v1.7.1-0.20250423082452-e16339a3962c/go.mod h1:XXG1eBJf+eeWacQx5azsQKL5Gg7jDYTFyyZGIa/56js= +github.com/FloatTech/AnimeAPI v1.7.1-0.20250530055006-50f5c7587c5b h1:H/1xpchTGmdoHqrszH4gjafCyHIhsGSFryAkBNsu8OI= +github.com/FloatTech/AnimeAPI v1.7.1-0.20250530055006-50f5c7587c5b/go.mod h1:XXG1eBJf+eeWacQx5azsQKL5Gg7jDYTFyyZGIa/56js= github.com/FloatTech/floatbox v0.0.0-20250513111443-adba80e84e80 h1:lFD1pd8NkYCrw0QpTX/T5pJ67I7AL5eGxQ4v0r9f81Q= github.com/FloatTech/floatbox v0.0.0-20250513111443-adba80e84e80/go.mod h1:IWoFFqu+0FeaHHQdddyiTRL5z7gJME6qHC96qh0R2sc= github.com/FloatTech/gg v1.1.3 h1:+GlL02lTKsxJQr4WCuNwVxC1/eBZrCvypCIBtxuOFb4= @@ -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.20250330125231-d8be1c9d3b9c h1:nIybmanPvQknseVOJ+s4/m3q7EZxtqMoTy3wiiZts6E= -github.com/FloatTech/zbputils v1.7.2-0.20250330125231-d8be1c9d3b9c/go.mod h1:ArZ0fMAcmPEIXOqDmfzbSx+oYH8sssApQnbCu694iS8= +github.com/FloatTech/zbputils v1.7.2-0.20250601064658-421e71926b83 h1:WfHzSblV7TZ/32cm1HUsfxTXUDKauzUYq5dbI1L+w3s= +github.com/FloatTech/zbputils v1.7.2-0.20250601064658-421e71926b83/go.mod h1:ArZ0fMAcmPEIXOqDmfzbSx+oYH8sssApQnbCu694iS8= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w= diff --git a/plugin/aichat/cfg.go b/plugin/aichat/cfg.go index 545e3e2c..2d40bf04 100644 --- a/plugin/aichat/cfg.go +++ b/plugin/aichat/cfg.go @@ -1,6 +1,7 @@ package aichat import ( + "strconv" "strings" ctrl "github.com/FloatTech/zbpctrl" @@ -17,6 +18,8 @@ var cfg = newconfig() type config struct { ModelName string Type int + MaxN uint + TopP float32 SystemP string API string Key string @@ -94,3 +97,57 @@ func newextrasetbool(ptr *bool) func(ctx *zero.Ctx) { ctx.SendChain(message.Text("成功")) } } + +func newextrasetuint(ptr *uint) func(ctx *zero.Ctx) { + return func(ctx *zero.Ctx) { + args := strings.TrimSpace(ctx.State["args"].(string)) + if args == "" { + ctx.SendChain(message.Text("ERROR: empty args")) + return + } + c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]) + if !ok { + ctx.SendChain(message.Text("ERROR: no such plugin")) + return + } + n, err := strconv.ParseUint(args, 10, 64) + if err != nil { + ctx.SendChain(message.Text("ERROR: parse args err: ", err)) + return + } + *ptr = uint(n) + err = c.SetExtra(&cfg) + if err != nil { + ctx.SendChain(message.Text("ERROR: set extra err: ", err)) + return + } + ctx.SendChain(message.Text("成功")) + } +} + +func newextrasetfloat32(ptr *float32) func(ctx *zero.Ctx) { + return func(ctx *zero.Ctx) { + args := strings.TrimSpace(ctx.State["args"].(string)) + if args == "" { + ctx.SendChain(message.Text("ERROR: empty args")) + return + } + c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]) + if !ok { + ctx.SendChain(message.Text("ERROR: no such plugin")) + return + } + n, err := strconv.ParseFloat(args, 32) + if err != nil { + ctx.SendChain(message.Text("ERROR: parse args err: ", err)) + return + } + *ptr = float32(n) + err = c.SetExtra(&cfg) + if err != nil { + ctx.SendChain(message.Text("ERROR: set extra err: ", err)) + return + } + ctx.SendChain(message.Text("成功")) + } +} diff --git a/plugin/aichat/main.go b/plugin/aichat/main.go index 25bd4dce..3cfa2240 100644 --- a/plugin/aichat/main.go +++ b/plugin/aichat/main.go @@ -36,7 +36,9 @@ var ( "- 重置AI聊天系统提示词\n" + "- 设置AI聊天系统提示词xxx\n" + "- 设置AI聊天分隔符(留空则清除)\n" + - "- 设置AI聊天(不)响应AT", + "- 设置AI聊天(不)响应AT\n" + + "- 设置AI聊天最大长度4096\n" + + "- 设置AI聊天TopP 0.9", PrivateDataFolder: "aichat", }) ) @@ -83,22 +85,30 @@ func init() { x := deepinfra.NewAPI(cfg.API, cfg.Key) var mod model.Protocol + maxn := cfg.MaxN + if maxn == 0 { + maxn = 4096 + } + topp := cfg.TopP + if topp == 0 { + topp = 0.9 + } switch cfg.Type { case 0: mod = model.NewOpenAI( cfg.ModelName, cfg.Separator, - float32(temp)/100, 0.9, 4096, + float32(temp)/100, topp, maxn, ) case 1: mod = model.NewOLLaMA( cfg.ModelName, cfg.Separator, - float32(temp)/100, 0.9, 4096, + float32(temp)/100, topp, maxn, ) case 2: mod = model.NewGenAI( cfg.ModelName, - float32(temp)/100, 0.9, 4096, + float32(temp)/100, topp, maxn, ) default: logrus.Warnln("[aichat] unsupported AI type", cfg.Type) @@ -255,4 +265,8 @@ func init() { Handle(newextrasetbool(&cfg.NoReplyAT)) en.OnRegex("^设置AI聊天(不)?支持系统提示词$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true). Handle(newextrasetbool(&cfg.NoSystemP)) + 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). + Handle(newextrasetfloat32(&cfg.TopP)) }