@nestim/koishi-plugin-qqgm-chat-style 1.0.5 → 1.0.6
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/index.js +2 -2
- package/lib/compact.js +12 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -95,8 +95,8 @@ const Config = Schema.intersect([
|
|
|
95
95
|
Schema.object({
|
|
96
96
|
compact: Schema.boolean().default(true)
|
|
97
97
|
.description('把主风格 skill 压缩成一张更短的风格卡(保留人设/语气/口癖,丢掉示例与说明),显著降低每次调用的输入 token。'),
|
|
98
|
-
compactMaxChars: Schema.natural().min(200).max(3000).default(
|
|
99
|
-
.description('
|
|
98
|
+
compactMaxChars: Schema.natural().min(200).max(3000).default(900)
|
|
99
|
+
.description('风格卡的字数上限(默认 900)。越小越省 token,但可能把锐评/暴论的骨架压丢;改小前先看卡片内容。'),
|
|
100
100
|
compactModel: Schema.string().default('')
|
|
101
101
|
.description('生成风格卡用的模型;留空沿用主插件的 aiModel。只在首次生成或 skill 正文变更时调用一次。'),
|
|
102
102
|
compactExtras: Schema.boolean().default(false)
|
package/lib/compact.js
CHANGED
|
@@ -19,10 +19,12 @@ const path = require('node:path');
|
|
|
19
19
|
|
|
20
20
|
const CACHE_FILE = '.style-cards.json';
|
|
21
21
|
const RETRY_MS = 10 * 60 * 1000;
|
|
22
|
+
/** 压缩提示词版本:改了提示词就 +1,缓存哈希跟着变,旧卡自动重生成 */
|
|
23
|
+
const PROMPT_VERSION = 2;
|
|
22
24
|
|
|
23
25
|
function hashSkill(skill) {
|
|
24
26
|
const body = String((skill && skill.body) || '');
|
|
25
|
-
return crypto.createHash('sha256').update(body).digest('hex').slice(0, 16);
|
|
27
|
+
return crypto.createHash('sha256').update(`${PROMPT_VERSION}|${body}`).digest('hex').slice(0, 16);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
function cleanCard(raw, maxChars) {
|
|
@@ -35,7 +37,7 @@ function cleanCard(raw, maxChars) {
|
|
|
35
37
|
.trim();
|
|
36
38
|
if (!text) return '';
|
|
37
39
|
|
|
38
|
-
const limit = Math.max(50, Number(maxChars) ||
|
|
40
|
+
const limit = Math.max(50, Number(maxChars) || 900);
|
|
39
41
|
if (text.length > limit) {
|
|
40
42
|
const slice = text.slice(0, limit);
|
|
41
43
|
const cut = Math.max(
|
|
@@ -66,12 +68,19 @@ function buildCompactPrompt(skill, maxChars) {
|
|
|
66
68
|
'- 高频口癖与语气词(挑最有辨识度的,不要抄整段);',
|
|
67
69
|
'- 明确的禁忌与边界。',
|
|
68
70
|
'',
|
|
71
|
+
'如果原文里写了下面这些「行为机制」,必须原样保留其骨架,不能只留态度:',
|
|
72
|
+
'- 模式与切换:接话 / 锐评 / 对线 / 收着说 分别在什么信号下触发、大概多长;',
|
|
73
|
+
'- 锐评与暴论的结构:先给结论、再给机制、最后补一刀;或者「接住 → 换层 → 给证据 → 补刀/留台阶」;',
|
|
74
|
+
'- 骂人分档与使用范围(哪些档位只能在对喷模式用)、对喷的退出条件;',
|
|
75
|
+
'- 什么时候必须收嘴、脱角色。',
|
|
76
|
+
'',
|
|
69
77
|
'必须丢掉:',
|
|
70
78
|
'- 背景故事、来源说明、示例对话、作者/版本/标签等元信息;',
|
|
71
79
|
'- 重复解释、教学式说明、“这段用来……”之类的描述。',
|
|
72
80
|
'',
|
|
73
81
|
'输出要求:',
|
|
74
82
|
`- 一张纯文本风格卡,不超过 ${maxChars} 字;`,
|
|
83
|
+
'- 锐评/暴论的部分宁可占篇幅,也不要压成一句“爱抬杠”;',
|
|
75
84
|
'- 接近字数上限时用一句完整的话收尾,不要截断在半句;',
|
|
76
85
|
'- 用第二人称写(“你说话……”),像给演员的角色提示;',
|
|
77
86
|
'- 不要标题、编号、列表、Markdown、代码块;',
|
|
@@ -96,7 +105,7 @@ class StyleCardStore {
|
|
|
96
105
|
this.config = options.config || {};
|
|
97
106
|
this.enabled = this.config.compact !== false;
|
|
98
107
|
const configured = Number(this.config.compactMaxChars);
|
|
99
|
-
this.maxChars = Math.max(200, Math.min(3000, Number.isFinite(configured) && configured > 0 ? configured :
|
|
108
|
+
this.maxChars = Math.max(200, Math.min(3000, Number.isFinite(configured) && configured > 0 ? configured : 900));
|
|
100
109
|
this.model = String(this.config.compactModel || '').trim();
|
|
101
110
|
|
|
102
111
|
this.texts = new Map();
|
package/package.json
CHANGED