mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
feat(aichat): add temp setting
This commit is contained in:
parent
3c7034e46c
commit
f73bf5a270
@ -1543,6 +1543,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/aichat"`
|
||||
|
||||
- [x] 设置AI聊天触发概率10
|
||||
- [x] 设置AI聊天温度80
|
||||
- [x] 设置AI聊天密钥xxx
|
||||
- [x] 设置AI聊天模型名xxx
|
||||
- [x] 设置AI聊天系统提示词xxx
|
||||
|
||||
@ -40,8 +40,8 @@ func (l *list) add(grp int64, txt string) {
|
||||
l.m[grp] = msgs
|
||||
}
|
||||
|
||||
func (l *list) body(mn, sysp string, grp int64) deepinfra.Model {
|
||||
m := model.NewCustom(mn, "", 0.7, 0.9, 1024).System(sysp)
|
||||
func (l *list) body(mn, sysp string, temp float32, grp int64) deepinfra.Model {
|
||||
m := model.NewCustom(mn, "", temp, 0.9, 1024).System(sysp)
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
for _, msg := range l.m[grp] {
|
||||
|
||||
@ -27,7 +27,7 @@ var (
|
||||
DisableOnDefault: false,
|
||||
Extra: control.ExtraFromString("aichat"),
|
||||
Brief: "OpenAI聊天",
|
||||
Help: "- 设置AI聊天触发概率10\n- 设置AI聊天密钥xxx\n- 设置AI聊天模型名xxx\n- 设置AI聊天系统提示词xxx",
|
||||
Help: "- 设置AI聊天触发概率10\n- 设置AI聊天温度80\n- 设置AI聊天密钥xxx\n- 设置AI聊天模型名xxx\n- 设置AI聊天系统提示词xxx",
|
||||
PrivateDataFolder: "aichat",
|
||||
})
|
||||
lst = newlist()
|
||||
@ -73,6 +73,8 @@ func init() {
|
||||
return
|
||||
}
|
||||
rate := c.GetData(gid)
|
||||
temp := (rate >> 8) & 0xff
|
||||
rate &= 0xff
|
||||
if !ctx.Event.IsToMe && rand.Intn(100) >= int(rate) {
|
||||
return
|
||||
}
|
||||
@ -94,7 +96,13 @@ func init() {
|
||||
} else {
|
||||
y = api
|
||||
}
|
||||
data, err := y.Request(lst.body(modelname, systemprompt, gid))
|
||||
if temp <= 0 {
|
||||
temp = 80 // default setting
|
||||
}
|
||||
if temp > 100 {
|
||||
temp = 100
|
||||
}
|
||||
data, err := y.Request(lst.body(modelname, systemprompt, float32(temp)/100, gid))
|
||||
if err != nil {
|
||||
logrus.Warnln("[niniqun] post err:", err)
|
||||
return
|
||||
@ -138,11 +146,50 @@ func init() {
|
||||
ctx.SendChain(message.Text("ERROR: parse rate err: ", err))
|
||||
return
|
||||
}
|
||||
if r > 100 {
|
||||
r = 100
|
||||
} else if r < 0 {
|
||||
r = 0
|
||||
}
|
||||
gid := ctx.Event.GroupID
|
||||
if gid == 0 {
|
||||
gid = -ctx.Event.UserID
|
||||
}
|
||||
err = c.SetData(gid, int64(r&0xff))
|
||||
val := c.GetData(gid) & (^0xff)
|
||||
err = c.SetData(gid, val|int64(r&0xff))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: set data err: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("成功"))
|
||||
})
|
||||
en.OnPrefix("设置AI聊天温度", zero.AdminPermission).SetBlock(true).Handle(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
|
||||
}
|
||||
r, err := strconv.Atoi(args)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: parse rate err: ", err))
|
||||
return
|
||||
}
|
||||
if r > 100 {
|
||||
r = 100
|
||||
} else if r < 0 {
|
||||
r = 0
|
||||
}
|
||||
gid := ctx.Event.GroupID
|
||||
if gid == 0 {
|
||||
gid = -ctx.Event.UserID
|
||||
}
|
||||
val := c.GetData(gid) & (^0xff00)
|
||||
err = c.SetData(gid, val|(int64(r&0xff)<<8))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: set data err: ", err))
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user