koishi-plugin-chat-model 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/index.js +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ npm install koishi-plugin-chat-model
|
|
|
40
40
|
| triggerPrefix | string | | 触发前缀,不填则任何未命中命令的消息都会触发 |
|
|
41
41
|
| triggerPrivate | boolean | true | 是否在私聊中自动触发 |
|
|
42
42
|
| triggerGroup | boolean | false | 是否在群聊中自动触发 |
|
|
43
|
+
| showThinkingMessage | boolean | false | 是否显示"正在思考中..."的消息,默认不显示 |
|
|
43
44
|
| customModelAdapter | string | | 自定义模型适配器路径(仅在modelType=custom时有效) |
|
|
44
45
|
| usageLimit.enabled | boolean | false | 是否启用使用限制 |
|
|
45
46
|
| usageLimit.maxMessagesPerUser | number | 100 | 每用户每日最大消息数 |
|
|
@@ -109,6 +110,17 @@ module.exports = CustomAdapter
|
|
|
109
110
|
- `chatModelContext`:存储用户的对话上下文
|
|
110
111
|
- `chatModelUsage`:存储用户的使用统计
|
|
111
112
|
|
|
113
|
+
## 版本更新
|
|
114
|
+
|
|
115
|
+
### v1.0.3
|
|
116
|
+
- 修复使用限制功能无法正常工作的问题
|
|
117
|
+
- 添加可选的"正在思考中..."消息配置,默认关闭
|
|
118
|
+
- 解决多余的"true"消息问题
|
|
119
|
+
|
|
120
|
+
### v1.0.2
|
|
121
|
+
- 修复了 `fetch is not a function` 错误
|
|
122
|
+
- 使用 node-fetch 和 abort-controller 替代内置 fetch
|
|
123
|
+
|
|
112
124
|
## 协议
|
|
113
125
|
|
|
114
126
|
MIT
|
package/index.js
CHANGED
|
@@ -22,6 +22,7 @@ exports.Config = Schema.object({
|
|
|
22
22
|
triggerPrefix: Schema.string().description('触发前缀,不填则任何未命中命令的消息都会触发模型响应'),
|
|
23
23
|
triggerPrivate: Schema.boolean().default(true).description('是否在私聊中自动触发'),
|
|
24
24
|
triggerGroup: Schema.boolean().default(false).description('是否在群聊中自动触发'),
|
|
25
|
+
showThinkingMessage: Schema.boolean().default(false).description('是否显示"正在思考中..."(默认: 不显示)'),
|
|
25
26
|
customModelAdapter: Schema.string().description('自定义模型适配器路径(仅modelType=custom时有效)'),
|
|
26
27
|
usageLimit: Schema.object({
|
|
27
28
|
enabled: Schema.boolean().default(false).description('是否启用使用限制'),
|
|
@@ -78,14 +79,16 @@ exports.apply = (ctx, config) => {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
// 检查用户使用限制
|
|
81
|
-
if (config.usageLimit?.enabled && !await checkUsageLimit(ctx, session.userId)) {
|
|
82
|
+
if (config.usageLimit?.enabled && !await checkUsageLimit(ctx, session.userId, config)) {
|
|
82
83
|
await session.send('今日对话次数已达上限,请明天再来')
|
|
83
84
|
return true
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
try {
|
|
87
|
-
//
|
|
88
|
-
|
|
88
|
+
// 可选显示"正在思考中..."的消息
|
|
89
|
+
if (config.showThinkingMessage) {
|
|
90
|
+
await session.sendQueued('正在思考中...')
|
|
91
|
+
}
|
|
89
92
|
|
|
90
93
|
// 处理消息并发送回复
|
|
91
94
|
const reply = await messageHandler(session, content)
|
|
@@ -302,7 +305,7 @@ async function checkAndResetUsage(ctx, userId, config) {
|
|
|
302
305
|
}
|
|
303
306
|
|
|
304
307
|
// 检查使用限制
|
|
305
|
-
async function checkUsageLimit(ctx, userId) {
|
|
308
|
+
async function checkUsageLimit(ctx, userId, config) {
|
|
306
309
|
const records = await ctx.database.get('chatModelUsage', { userId })
|
|
307
310
|
|
|
308
311
|
if (!records || records.length === 0) {
|
|
@@ -322,7 +325,6 @@ async function checkUsageLimit(ctx, userId) {
|
|
|
322
325
|
}
|
|
323
326
|
|
|
324
327
|
// 返回是否未超过限制
|
|
325
|
-
const config = ctx.config.chatModel
|
|
326
328
|
return record.dailyCount < (config.usageLimit?.maxMessagesPerUser || 100)
|
|
327
329
|
}
|
|
328
330
|
|