Skip to content

Commit 7cf6ccc

Browse files
committed
✨ 添加以语音输出
1 parent 007ee1d commit 7cf6ccc

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

plugin/aichat/cfg.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type config struct {
2929
Separator string
3030
NoReplyAT bool
3131
NoSystemP bool
32+
NoRecord bool
3233
}
3334

3435
func newconfig() config {
@@ -155,19 +156,30 @@ func newextrasetfloat32(ptr *float32) func(ctx *zero.Ctx) {
155156
}
156157
}
157158

158-
func printConfig(cfg config) string {
159+
func printConfig(rate int64, temperature int64, cfg config) string {
160+
maxn := cfg.MaxN
161+
if maxn == 0 {
162+
maxn = 4096
163+
}
164+
topp := cfg.TopP
165+
if topp == 0 {
166+
topp = 0.9
167+
}
159168
var builder strings.Builder
160169
builder.WriteString("当前AI聊天配置:\n")
161170
builder.WriteString(fmt.Sprintf("• 模型名:%s\n", cfg.ModelName))
162-
builder.WriteString(fmt.Sprintf("• 触发概率:%d%%\n", cfg.Type))
163-
builder.WriteString(fmt.Sprintf("• 最大生成长度:%d\n", cfg.MaxN))
164-
builder.WriteString(fmt.Sprintf("• TopP采样值:%.1f\n", cfg.TopP))
171+
builder.WriteString(fmt.Sprintf("• 接口类型:%d(%s)\n", cfg.Type, apilist[cfg.Type]))
172+
builder.WriteString(fmt.Sprintf("• 触发概率:%d%%\n", rate))
173+
builder.WriteString(fmt.Sprintf("• 温度:%.2f\n", float32(temperature)/100))
174+
builder.WriteString(fmt.Sprintf("• 最大长度:%d\n", maxn))
175+
builder.WriteString(fmt.Sprintf("• TopP:%.1f\n", topp))
165176
builder.WriteString(fmt.Sprintf("• 系统提示词:%s\n", cfg.SystemP))
166177
builder.WriteString(fmt.Sprintf("• 接口地址:%s\n", cfg.API))
167178
builder.WriteString(fmt.Sprintf("• 密钥:%s\n", maskKey(cfg.Key)))
168179
builder.WriteString(fmt.Sprintf("• 分隔符:%s\n", cfg.Separator))
169180
builder.WriteString(fmt.Sprintf("• 响应@:%s\n", yesNo(!cfg.NoReplyAT)))
170181
builder.WriteString(fmt.Sprintf("• 支持系统提示词:%s\n", yesNo(!cfg.NoSystemP)))
182+
builder.WriteString(fmt.Sprintf("• 以AI语音输出:%s\n", yesNo(!cfg.NoRecord)))
171183
return builder.String()
172184
}
173185

plugin/aichat/main.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package aichat
33

44
import (
5-
"fmt"
65
"math/rand"
76
"strconv"
87
"strings"
@@ -41,8 +40,8 @@ var (
4140
"- 设置AI聊天(不)响应AT\n" +
4241
"- 设置AI聊天最大长度4096\n" +
4342
"- 设置AI聊天TopP 0.9\n" +
44-
"- 查看AI聊天配置\n" +
45-
"- [启用|禁用]AI语音\n",
43+
"- 设置AI聊天(不)以AI语音输出\n" +
44+
"- 查看AI聊天配置\n",
4645
PrivateDataFolder: "aichat",
4746
})
4847
)
@@ -53,6 +52,7 @@ var (
5352
"OLLaMA": 1,
5453
"GenAI": 2,
5554
}
55+
apilist = [3]string{"OpenAI", "OLLaMA", "GenAI"}
5656
)
5757

5858
func init() {
@@ -141,12 +141,25 @@ func init() {
141141
if t == "" {
142142
continue
143143
}
144+
logrus.Infoln("[aichat] 回复内容:", t)
144145
recCfg := airecord.GetRecordConfig()
145-
fmt.Println(recCfg)
146-
if id != nil {
147-
id = ctx.SendChain(message.Reply(id), message.Text(t))
146+
if !cfg.NoRecord {
147+
record := ctx.GetAIRecord(recCfg.ModelID, recCfg.Customgid, t).String()
148+
if record != "" {
149+
ctx.SendChain(message.Record(record))
150+
} else {
151+
if id != nil {
152+
id = ctx.SendChain(message.Reply(id), message.Text(t))
153+
} else {
154+
id = ctx.SendChain(message.Text(t))
155+
}
156+
}
148157
} else {
149-
id = ctx.SendChain(message.Text(t))
158+
if id != nil {
159+
id = ctx.SendChain(message.Reply(id), message.Text(t))
160+
} else {
161+
id = ctx.SendChain(message.Text(t))
162+
}
150163
}
151164
process.SleepAbout1sTo2s()
152165
}
@@ -277,8 +290,24 @@ func init() {
277290
Handle(newextrasetuint(&cfg.MaxN))
278291
en.OnPrefix("设置AI聊天TopP", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
279292
Handle(newextrasetfloat32(&cfg.TopP))
293+
en.OnRegex("^设置AI聊天(不)?以AI语音输出$", ensureconfig, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).
294+
Handle(newextrasetbool(&cfg.NoRecord))
280295
en.OnFullMatch("查看AI聊天配置", ensureconfig).SetBlock(true).
281296
Handle(func(ctx *zero.Ctx) {
282-
ctx.SendChain(message.Text(printConfig(cfg)))
297+
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
298+
if !ok {
299+
ctx.SendChain(message.Text("ERROR: no such plugin"))
300+
return
301+
}
302+
gid := ctx.Event.GroupID
303+
rate := c.GetData(gid) & 0xff
304+
temp := (c.GetData(gid) >> 8) & 0xff
305+
if temp <= 0 {
306+
temp = 70 // default setting
307+
}
308+
if temp > 100 {
309+
temp = 100
310+
}
311+
ctx.SendChain(message.Text(printConfig(rate, temp, cfg)))
283312
})
284313
}

0 commit comments

Comments
 (0)