mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
optimize(aichat): context
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
"github.com/FloatTech/floatbox/process"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/chat"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
)
|
||||
|
||||
@@ -35,7 +36,6 @@ var (
|
||||
"- 设置AI聊天分隔符</think>(留空则清除)",
|
||||
PrivateDataFolder: "aichat",
|
||||
})
|
||||
lst = newlist()
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -74,9 +74,7 @@ func init() {
|
||||
}
|
||||
|
||||
en.OnMessage(func(ctx *zero.Ctx) bool {
|
||||
txt := ctx.ExtractPlainText()
|
||||
ctx.State["aichat_txt"] = txt
|
||||
return txt != ""
|
||||
return ctx.ExtractPlainText() != ""
|
||||
}).SetBlock(false).Handle(func(ctx *zero.Ctx) {
|
||||
gid := ctx.Event.GroupID
|
||||
if gid == 0 {
|
||||
@@ -86,7 +84,6 @@ func init() {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
lst.add(gid, ctx.State["aichat_txt"].(string))
|
||||
rate := c.GetData(gid)
|
||||
temp := (rate >> 8) & 0xff
|
||||
rate &= 0xff
|
||||
@@ -117,14 +114,14 @@ func init() {
|
||||
if temp > 100 {
|
||||
temp = 100
|
||||
}
|
||||
data, err := y.Request(lst.body(modelname, systemprompt, float32(temp)/100, gid))
|
||||
data, err := y.Request(chat.Ask(ctx, float32(temp)/100, modelname, systemprompt, sepstr))
|
||||
if err != nil {
|
||||
logrus.Warnln("[niniqun] post err:", err)
|
||||
return
|
||||
}
|
||||
txt := strings.Trim(data, "\n ")
|
||||
if len(txt) > 0 {
|
||||
lst.add(gid, txt)
|
||||
chat.Reply(ctx, txt)
|
||||
nick := zero.BotConfig.NickName[rand.Intn(len(zero.BotConfig.NickName))]
|
||||
txt = strings.ReplaceAll(txt, "{name}", ctx.CardOrNickName(ctx.Event.UserID))
|
||||
txt = strings.ReplaceAll(txt, "{me}", nick)
|
||||
|
||||
Reference in New Issue
Block a user