fix(aichat): some errors

This commit is contained in:
源文雨 2025-02-15 12:38:43 +09:00
parent 512561d8fd
commit 112328a7f2
3 changed files with 22 additions and 14 deletions

View File

@ -1547,7 +1547,7 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 设置AI聊天密钥xxx
- [x] 设置AI聊天模型名xxx
- [x] 设置AI聊天系统提示词xxx
- [x] 设置AI聊天分隔符`</think>`
- [x] 设置AI聊天分隔符`</think>`(留空则清除)
</details>
<details>

View File

@ -1,6 +1,7 @@
package aichat
import (
"strings"
"sync"
"github.com/fumiama/deepinfra"
@ -37,15 +38,15 @@ func (l *list) add(grp int64, txt string) {
}
copy(msgs, msgs[1:])
msgs[len(msgs)-1] = txt
l.m[grp] = msgs
}
func (l *list) body(mn, sysp string, temp float32, grp int64) deepinfra.Model {
m := model.NewCustom(mn, sepstr, temp, 0.9, 1024).System(sysp)
l.mu.RLock()
defer l.mu.RUnlock()
for _, msg := range l.m[grp] {
_ = m.User(msg)
sz := len(l.m[grp])
if sz == 0 {
return m.User("自己随机开启新话题")
}
return m
return m.User(strings.Join(l.m[grp], "\n\n"))
}

View File

@ -24,10 +24,15 @@ import (
var (
api *deepinfra.API
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Extra: control.ExtraFromString("aichat"),
Brief: "OpenAI聊天",
Help: "- 设置AI聊天触发概率10\n- 设置AI聊天温度80\n- 设置AI聊天密钥xxx\n- 设置AI聊天模型名xxx\n- 设置AI聊天系统提示词xxx\n- 设置AI聊天分隔符</think>",
DisableOnDefault: false,
Extra: control.ExtraFromString("aichat"),
Brief: "OpenAI聊天",
Help: "- 设置AI聊天触发概率10\n" +
"- 设置AI聊天温度80\n" +
"- 设置AI聊天密钥xxx\n" +
"- 设置AI聊天模型名xxx\n" +
"- 设置AI聊天系统提示词xxx\n" +
"- 设置AI聊天分隔符</think>(留空则清除)",
PrivateDataFolder: "aichat",
})
lst = newlist()
@ -73,7 +78,6 @@ func init() {
ctx.State["aichat_txt"] = txt
return txt != ""
}).SetBlock(false).Handle(func(ctx *zero.Ctx) {
lst.add(ctx.Event.GroupID, ctx.State["aichat_txt"].(string))
gid := ctx.Event.GroupID
if gid == 0 {
gid = -ctx.Event.UserID
@ -82,6 +86,7 @@ func init() {
if !ok {
return
}
lst.add(gid, ctx.State["aichat_txt"].(string))
rate := c.GetData(gid)
temp := (rate >> 8) & 0xff
rate &= 0xff
@ -107,7 +112,7 @@ func init() {
y = api
}
if temp <= 0 {
temp = 80 // default setting
temp = 70 // default setting
}
if temp > 100 {
temp = 100
@ -119,7 +124,7 @@ func init() {
}
txt := strings.Trim(data, "\n  ")
if len(txt) > 0 {
lst.add(ctx.Event.GroupID, txt)
lst.add(gid, 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)
@ -255,7 +260,9 @@ func init() {
en.OnPrefix("设置AI聊天分隔符", zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
args := strings.TrimSpace(ctx.State["args"].(string))
if args == "" {
ctx.SendChain(message.Text("ERROR: empty args"))
sepstr = ""
_ = os.Remove(pf)
ctx.SendChain(message.Text("清除成功"))
return
}
sepstr = args
@ -264,6 +271,6 @@ func init() {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("成功"))
ctx.SendChain(message.Text("设置成功"))
})
}