koishi-plugin-chatluna-character 0.0.44 → 0.0.46
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/plugins/chat.js +8 -5
- package/lib/service/message.js +4 -1
- package/package.json +6 -6
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 = void 0;
|
|
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
|
}
|
|
@@ -107,7 +107,7 @@ async function apply(ctx, config) {
|
|
|
107
107
|
parsedResponse.rawMessage.length * copyOfConfig.typingTime +
|
|
108
108
|
100;
|
|
109
109
|
await (0, koishi_1.sleep)(random.int(maxTime / 4, maxTime / 2));
|
|
110
|
-
await session.send(await ctx.vits.say({ input:
|
|
110
|
+
await session.send(await ctx.vits.say({ input: parsedResponse.rawMessage }));
|
|
111
111
|
break;
|
|
112
112
|
}
|
|
113
113
|
try {
|
|
@@ -141,6 +141,7 @@ async function apply(ctx, config) {
|
|
|
141
141
|
await service.broadcastOnBot(session, parsedResponse.elements.flat());
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
+
exports.apply = apply;
|
|
144
145
|
function isEmoticonStatement(text) {
|
|
145
146
|
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;
|
|
146
147
|
return regex.test(text);
|
|
@@ -343,9 +344,11 @@ async function formatMessage(messages, config, model, systemPrompt, historyPromp
|
|
|
343
344
|
currentTokens += await model.getNumTokens(systemPrompt);
|
|
344
345
|
currentTokens += await model.getNumTokens(historyPrompt);
|
|
345
346
|
const calculatedMessages = [];
|
|
347
|
+
const random = new koishi_1.Random();
|
|
346
348
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
347
349
|
const message = messages[i];
|
|
348
|
-
const
|
|
350
|
+
const voiceProbability = random.int(1, 10) > 5 ? 'voice' : 'text';
|
|
351
|
+
const jsonMessage = `{"name":"${message.name}","id":"${message.id}","content":${JSON.stringify(message.content)}","type":"${voiceProbability}"}`;
|
|
349
352
|
const jsonMessageToken = await model.getNumTokens(jsonMessage);
|
|
350
353
|
if (currentTokens + jsonMessageToken > maxTokens - 4) {
|
|
351
354
|
break;
|
package/lib/service/message.js
CHANGED
|
@@ -105,6 +105,9 @@ class MessageCollector extends koishi_1.Service {
|
|
|
105
105
|
else {
|
|
106
106
|
this._messages = {};
|
|
107
107
|
}
|
|
108
|
+
this._groupTemp[groupId] = {
|
|
109
|
+
completionMessages: []
|
|
110
|
+
};
|
|
108
111
|
}
|
|
109
112
|
async broadcastOnBot(session, elements) {
|
|
110
113
|
if (session.isDirect) {
|
|
@@ -197,7 +200,7 @@ function mapElementToString(session, content, elements) {
|
|
|
197
200
|
for (const element of elements) {
|
|
198
201
|
if (element.type === 'text') {
|
|
199
202
|
const content = element.attrs.content;
|
|
200
|
-
if (content
|
|
203
|
+
if (content?.trimEnd()?.length > 0) {
|
|
201
204
|
filteredBuffer.push(content);
|
|
202
205
|
}
|
|
203
206
|
}
|
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.46",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -31,10 +31,11 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/ChatLunaLab/chatluna-character#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@langchain/core": "^0.1.
|
|
34
|
+
"@langchain/core": "^0.1.58",
|
|
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,12 +48,11 @@
|
|
|
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
|
-
"
|
|
51
|
-
"koishi": "^4.17.2"
|
|
51
|
+
"koishi": "^4.17.4"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"koishi": "^4.17.
|
|
55
|
-
"koishi-plugin-chatluna": "^1.0.0-beta.
|
|
54
|
+
"koishi": "^4.17.4",
|
|
55
|
+
"koishi-plugin-chatluna": "^1.0.0-beta.44"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=18.0.0"
|