mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
feat(aichat): add temp setting
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user