koishi-plugin-chatluna-character 0.0.43 → 0.0.45
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/lib/plugin.js +1 -2
- package/lib/plugins/chat.js +12 -8
- package/lib/service/message.js +3 -0
- package/package.json +5 -2
package/lib/plugin.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.plugins =
|
|
6
|
+
exports.plugins = plugins;
|
|
7
7
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
async function plugins(ctx, config) {
|
|
@@ -18,4 +18,3 @@ async function plugins(ctx, config) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.plugins = plugins;
|
package/lib/plugins/chat.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.apply =
|
|
3
|
+
exports.apply = apply;
|
|
4
4
|
const messages_1 = require("@langchain/core/messages");
|
|
5
5
|
const koishi_1 = require("koishi");
|
|
6
6
|
const count_tokens_1 = require("koishi-plugin-chatluna/lib/llm-core/utils/count_tokens");
|
|
@@ -86,8 +86,8 @@ async function apply(ctx, config) {
|
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
temp.completionMessages.push(humanMessage, responseMessage);
|
|
89
|
-
if (temp.completionMessages.length >
|
|
90
|
-
while (temp.completionMessages.length <=
|
|
89
|
+
if (temp.completionMessages.length > 8) {
|
|
90
|
+
while (temp.completionMessages.length <= 4) {
|
|
91
91
|
temp.completionMessages.shift();
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -101,12 +101,13 @@ async function apply(ctx, config) {
|
|
|
101
101
|
isEmoticonStatement(text)) {
|
|
102
102
|
continue;
|
|
103
103
|
}
|
|
104
|
-
if (config.splitVoice !== true
|
|
104
|
+
if (config.splitVoice !== true &&
|
|
105
|
+
parsedResponse.messageType === 'voice') {
|
|
105
106
|
maxTime =
|
|
106
107
|
parsedResponse.rawMessage.length * copyOfConfig.typingTime +
|
|
107
108
|
100;
|
|
108
109
|
await (0, koishi_1.sleep)(random.int(maxTime / 4, maxTime / 2));
|
|
109
|
-
await session.send(await ctx.vits.say({ input:
|
|
110
|
+
await session.send(await ctx.vits.say({ input: parsedResponse.rawMessage }));
|
|
110
111
|
break;
|
|
111
112
|
}
|
|
112
113
|
try {
|
|
@@ -116,11 +117,13 @@ async function apply(ctx, config) {
|
|
|
116
117
|
await session.send(elements);
|
|
117
118
|
break;
|
|
118
119
|
case 'voice':
|
|
119
|
-
await (0, koishi_1.sleep)(random.int(maxTime / 4, maxTime / 2));
|
|
120
120
|
await session.send(await ctx.vits.say({
|
|
121
121
|
input: text
|
|
122
122
|
}));
|
|
123
123
|
break;
|
|
124
|
+
default:
|
|
125
|
+
await session.send(elements);
|
|
126
|
+
break;
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
catch (e) {
|
|
@@ -138,7 +141,6 @@ async function apply(ctx, config) {
|
|
|
138
141
|
await service.broadcastOnBot(session, parsedResponse.elements.flat());
|
|
139
142
|
});
|
|
140
143
|
}
|
|
141
|
-
exports.apply = apply;
|
|
142
144
|
function isEmoticonStatement(text) {
|
|
143
145
|
const regex = /^[\p{P}\p{S}\p{Z}\p{M}\p{N}\p{L}\s]*\p{So}[\p{P}\p{S}\p{Z}\p{M}\p{N}\p{L}\s]*$/u;
|
|
144
146
|
return regex.test(text);
|
|
@@ -341,9 +343,11 @@ async function formatMessage(messages, config, model, systemPrompt, historyPromp
|
|
|
341
343
|
currentTokens += await model.getNumTokens(systemPrompt);
|
|
342
344
|
currentTokens += await model.getNumTokens(historyPrompt);
|
|
343
345
|
const calculatedMessages = [];
|
|
346
|
+
const random = new koishi_1.Random();
|
|
344
347
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
345
348
|
const message = messages[i];
|
|
346
|
-
const
|
|
349
|
+
const voiceProbability = random.int(1, 10) > 5 ? 'voice' : 'text';
|
|
350
|
+
const jsonMessage = `{"name":"${message.name}","id":"${message.id}","content":${JSON.stringify(message.content)}","type":"${voiceProbability}"}`;
|
|
347
351
|
const jsonMessageToken = await model.getNumTokens(jsonMessage);
|
|
348
352
|
if (currentTokens + jsonMessageToken > maxTokens - 4) {
|
|
349
353
|
break;
|
package/lib/service/message.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chatluna-character",
|
|
3
3
|
"description": "Let the large language model play a role, disguise as a group friend",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.45",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"js-yaml": "^4.1.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
+
"@initencounter/vits": "^0.0.3",
|
|
38
39
|
"@typescript-eslint/eslint-plugin": "^6.21.1-alpha.1",
|
|
39
40
|
"@typescript-eslint/parser": "^6.21.1-alpha.1",
|
|
40
41
|
"atsc": "^1.2.2",
|
|
@@ -47,7 +48,6 @@
|
|
|
47
48
|
"eslint-plugin-n": "^16.6.2",
|
|
48
49
|
"eslint-plugin-prettier": "^5.1.3",
|
|
49
50
|
"eslint-plugin-promise": "^6.1.1",
|
|
50
|
-
"@initencounter/vits": "^0.0.3",
|
|
51
51
|
"koishi": "^4.17.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
@@ -71,6 +71,9 @@
|
|
|
71
71
|
"service": {
|
|
72
72
|
"required": [
|
|
73
73
|
"chatluna"
|
|
74
|
+
],
|
|
75
|
+
"optional": [
|
|
76
|
+
"vits"
|
|
74
77
|
]
|
|
75
78
|
}
|
|
76
79
|
}
|