mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
fix(aichat): some errors
This commit is contained in:
parent
512561d8fd
commit
112328a7f2
@ -1547,7 +1547,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
- [x] 设置AI聊天密钥xxx
|
- [x] 设置AI聊天密钥xxx
|
||||||
- [x] 设置AI聊天模型名xxx
|
- [x] 设置AI聊天模型名xxx
|
||||||
- [x] 设置AI聊天系统提示词xxx
|
- [x] 设置AI聊天系统提示词xxx
|
||||||
- [x] 设置AI聊天分隔符`</think>`
|
- [x] 设置AI聊天分隔符`</think>`(留空则清除)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package aichat
|
package aichat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/fumiama/deepinfra"
|
"github.com/fumiama/deepinfra"
|
||||||
@ -37,15 +38,15 @@ func (l *list) add(grp int64, txt string) {
|
|||||||
}
|
}
|
||||||
copy(msgs, msgs[1:])
|
copy(msgs, msgs[1:])
|
||||||
msgs[len(msgs)-1] = txt
|
msgs[len(msgs)-1] = txt
|
||||||
l.m[grp] = msgs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *list) body(mn, sysp string, temp float32, grp int64) deepinfra.Model {
|
func (l *list) body(mn, sysp string, temp float32, grp int64) deepinfra.Model {
|
||||||
m := model.NewCustom(mn, sepstr, temp, 0.9, 1024).System(sysp)
|
m := model.NewCustom(mn, sepstr, temp, 0.9, 1024).System(sysp)
|
||||||
l.mu.RLock()
|
l.mu.RLock()
|
||||||
defer l.mu.RUnlock()
|
defer l.mu.RUnlock()
|
||||||
for _, msg := range l.m[grp] {
|
sz := len(l.m[grp])
|
||||||
_ = m.User(msg)
|
if sz == 0 {
|
||||||
|
return m.User("自己随机开启新话题")
|
||||||
}
|
}
|
||||||
return m
|
return m.User(strings.Join(l.m[grp], "\n\n"))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,10 +24,15 @@ import (
|
|||||||
var (
|
var (
|
||||||
api *deepinfra.API
|
api *deepinfra.API
|
||||||
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Extra: control.ExtraFromString("aichat"),
|
Extra: control.ExtraFromString("aichat"),
|
||||||
Brief: "OpenAI聊天",
|
Brief: "OpenAI聊天",
|
||||||
Help: "- 设置AI聊天触发概率10\n- 设置AI聊天温度80\n- 设置AI聊天密钥xxx\n- 设置AI聊天模型名xxx\n- 设置AI聊天系统提示词xxx\n- 设置AI聊天分隔符</think>",
|
Help: "- 设置AI聊天触发概率10\n" +
|
||||||
|
"- 设置AI聊天温度80\n" +
|
||||||
|
"- 设置AI聊天密钥xxx\n" +
|
||||||
|
"- 设置AI聊天模型名xxx\n" +
|
||||||
|
"- 设置AI聊天系统提示词xxx\n" +
|
||||||
|
"- 设置AI聊天分隔符</think>(留空则清除)",
|
||||||
PrivateDataFolder: "aichat",
|
PrivateDataFolder: "aichat",
|
||||||
})
|
})
|
||||||
lst = newlist()
|
lst = newlist()
|
||||||
@ -73,7 +78,6 @@ func init() {
|
|||||||
ctx.State["aichat_txt"] = txt
|
ctx.State["aichat_txt"] = txt
|
||||||
return txt != ""
|
return txt != ""
|
||||||
}).SetBlock(false).Handle(func(ctx *zero.Ctx) {
|
}).SetBlock(false).Handle(func(ctx *zero.Ctx) {
|
||||||
lst.add(ctx.Event.GroupID, ctx.State["aichat_txt"].(string))
|
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
if gid == 0 {
|
if gid == 0 {
|
||||||
gid = -ctx.Event.UserID
|
gid = -ctx.Event.UserID
|
||||||
@ -82,6 +86,7 @@ func init() {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
lst.add(gid, ctx.State["aichat_txt"].(string))
|
||||||
rate := c.GetData(gid)
|
rate := c.GetData(gid)
|
||||||
temp := (rate >> 8) & 0xff
|
temp := (rate >> 8) & 0xff
|
||||||
rate &= 0xff
|
rate &= 0xff
|
||||||
@ -107,7 +112,7 @@ func init() {
|
|||||||
y = api
|
y = api
|
||||||
}
|
}
|
||||||
if temp <= 0 {
|
if temp <= 0 {
|
||||||
temp = 80 // default setting
|
temp = 70 // default setting
|
||||||
}
|
}
|
||||||
if temp > 100 {
|
if temp > 100 {
|
||||||
temp = 100
|
temp = 100
|
||||||
@ -119,7 +124,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
txt := strings.Trim(data, "\n ")
|
txt := strings.Trim(data, "\n ")
|
||||||
if len(txt) > 0 {
|
if len(txt) > 0 {
|
||||||
lst.add(ctx.Event.GroupID, txt)
|
lst.add(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)
|
||||||
@ -255,7 +260,9 @@ func init() {
|
|||||||
en.OnPrefix("设置AI聊天分隔符", zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
en.OnPrefix("设置AI聊天分隔符", zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
args := strings.TrimSpace(ctx.State["args"].(string))
|
args := strings.TrimSpace(ctx.State["args"].(string))
|
||||||
if args == "" {
|
if args == "" {
|
||||||
ctx.SendChain(message.Text("ERROR: empty args"))
|
sepstr = ""
|
||||||
|
_ = os.Remove(pf)
|
||||||
|
ctx.SendChain(message.Text("清除成功"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sepstr = args
|
sepstr = args
|
||||||
@ -264,6 +271,6 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.SendChain(message.Text("成功"))
|
ctx.SendChain(message.Text("设置成功"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user