koishi-plugin-p-draw 1.6.0 → 1.6.2
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 +142 -98
- package/lib/i18n.js +1 -1
- package/lib/parse.js +45 -0
- package/package.json +1 -1
- package/readme.md +108 -23
package/index.js
CHANGED
|
@@ -25,6 +25,7 @@ exports.usage = `
|
|
|
25
25
|
别名:部署诊断
|
|
26
26
|
输出更详细的配置与连通性诊断。
|
|
27
27
|
- **尺寸:** 支持 \`竖图\` \`横图\` \`方图\` \`长竖图\` \`宽屏\` 或在描述中写 \`1024x1536:描述\` / \`--尺寸 1216x832\`。
|
|
28
|
+
- **采样参数:** 描述里可写 \`--steps 40\` / \`--cfg 3.5\`(也可写 \`--步数\` / \`--强度\`)临时覆盖步数与 CFG,优先于 \`modelParams\` 与全局配置。
|
|
28
29
|
- **原样模式:** 描述前加 \`无优化\` 直接提交写好的 tags。
|
|
29
30
|
- **联网搜索:** 描述中带 \`联网\` / \`搜索\` / \`查一下\` 等词时,会先联网搜索补充角色设定(需配置 Tavily Key)。
|
|
30
31
|
- **画师组:** \`创建画师组 名称=tags\` \`切换画师组 名称\` \`查看画师组\` \`删除画师组 名称\`
|
|
@@ -32,99 +33,123 @@ exports.usage = `
|
|
|
32
33
|
`;
|
|
33
34
|
|
|
34
35
|
const { zhCN } = require('./lib/i18n')
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Schema.
|
|
55
|
-
Schema.
|
|
56
|
-
Schema.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
samplerName: Schema.string().
|
|
60
|
-
scheduler: Schema.string().
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}).
|
|
36
|
+
// 配置分组:用 Schema.intersect 让控制台按「可折叠小节」渲染,
|
|
37
|
+
// 同时解析结果仍是扁平对象 —— 旧的 koishi.yml 键名不变,无需迁移。
|
|
38
|
+
exports.Config = Schema.intersect([
|
|
39
|
+
// ---------------- 常用(默认展开) ----------------
|
|
40
|
+
Schema.object({
|
|
41
|
+
comfyuiBaseUrl: Schema.string().default('http://127.0.0.1:8188').description('ComfyUI 地址'),
|
|
42
|
+
timeout: Schema.number().default(300).description('单次生成超时(秒)'),
|
|
43
|
+
pollInterval: Schema.number().default(2).description('生成状态查询间隔(秒)'),
|
|
44
|
+
}).description('① ComfyUI 连接'),
|
|
45
|
+
|
|
46
|
+
Schema.object({
|
|
47
|
+
unetName: Schema.string().default('anima-aesthetic-v1.1.safetensors').description('主模型文件名,需与 ComfyUI models/diffusion_models 下的文件名完全一致;8G 显存可填 .gguf 版(插件自动改用 UnetLoaderGGUF)'),
|
|
48
|
+
useGgufUnet: Schema.union([
|
|
49
|
+
Schema.const('auto').description('按文件名自动判断(.gguf → UnetLoaderGGUF)'),
|
|
50
|
+
Schema.const('true').description('强制 UnetLoaderGGUF(需安装 ComfyUI-GGUF)'),
|
|
51
|
+
Schema.const('false').description('强制原生 UNETLoader'),
|
|
52
|
+
]).default('auto').description('主模型加载方式'),
|
|
53
|
+
clipName: Schema.string().default('qwen_3_06b_base.safetensors').description('文本编码器文件名(ComfyUI models/text_encoders)'),
|
|
54
|
+
vaeName: Schema.string().default('qwen_image_vae.safetensors').description('VAE 文件名(ComfyUI models/vae)'),
|
|
55
|
+
width: Schema.number().default(832).description('默认宽度'),
|
|
56
|
+
height: Schema.number().default(1216).description('默认高度'),
|
|
57
|
+
allowedSizes: Schema.array(Schema.string()).default(['832x1216', '896x1152', '1024x1024', '1152x896', '1216x832', '768x1344', '1344x768', '1024x1536']).description('可用尺寸列表(宽x高)'),
|
|
58
|
+
steps: Schema.number().default(30).description('采样步数'),
|
|
59
|
+
cfg: Schema.number().default(4.0).description('CFG 强度(Aesthetic 1.1 推荐 4,用 3 也常更好)'),
|
|
60
|
+
samplerName: Schema.string().default('er_sde').description('采样器'),
|
|
61
|
+
scheduler: Schema.string().default('simple').description('调度器'),
|
|
62
|
+
}).description('② 模型与采样参数'),
|
|
63
|
+
|
|
64
|
+
Schema.object({
|
|
65
|
+
qualityPrefix: Schema.string().default('').description('质量词前缀(Aesthetic 1.1 建议留空;Base 模型可填 masterpiece, best quality, score_7)'),
|
|
66
|
+
negativePrompt: Schema.string().default('worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts').description('负面提示词'),
|
|
67
|
+
styleTags: Schema.string().default('').description('画风 tags'),
|
|
68
|
+
defaultArtistTags: Schema.string().default('').description('备用画师 tags'),
|
|
69
|
+
activeArtistPreset: Schema.string().default('').description('启用的画师组名称'),
|
|
70
|
+
artistPresets: Schema.array(Schema.string()).default([]).description('画师组(格式:名称=tags)'),
|
|
71
|
+
fixedCharacters: Schema.array(Schema.string()).default([]).description('固定角色(格式:角色名=tags;仅兼容旧配置,运行时以数据库为准)'),
|
|
72
|
+
}).description('③ 提示词与画师'),
|
|
73
|
+
|
|
74
|
+
Schema.object({
|
|
75
|
+
queueEnabled: Schema.boolean().default(true).description('启用生成队列(逐张顺序执行)'),
|
|
76
|
+
queueMaxRequests: Schema.number().default(5).description('队列最大任务数(0 表示不限制)'),
|
|
77
|
+
batchMax: Schema.number().default(4).description('单次指令最多生成的张数'),
|
|
78
|
+
}).description('④ 队列与批量'),
|
|
79
|
+
|
|
80
|
+
Schema.object({
|
|
81
|
+
price: Schema.number().default(500).description('一张图消耗的 P 点'),
|
|
82
|
+
multiPrice: Schema.number().default(900).description('多人指令单张消耗的 P 点'),
|
|
83
|
+
couponPrice: Schema.number().default(3000).description('提示词优化券单价(可被 data/p-shop.json 覆盖)'),
|
|
84
|
+
couponAskTimeout: Schema.number().default(60).description('优化券确认等待时间(秒)'),
|
|
85
|
+
adminUsers: Schema.array(Schema.string()).default([]).description('免 P 点管理员用户 ID'),
|
|
86
|
+
}).description('⑤ P 点与优化券'),
|
|
87
|
+
|
|
88
|
+
Schema.object({
|
|
89
|
+
adminOnly: Schema.boolean().default(false).description('仅管理员可用'),
|
|
90
|
+
allowedUserIds: Schema.array(Schema.string()).default([]).description('用户白名单(留空不限制)'),
|
|
91
|
+
blockedUserIds: Schema.array(Schema.string()).default([]).description('用户黑名单(优先于白名单)'),
|
|
92
|
+
allowedGroupIds: Schema.array(Schema.string()).default([]).description('群白名单(留空不限制)'),
|
|
93
|
+
blockedGroupIds: Schema.array(Schema.string()).default([]).description('群黑名单(优先于白名单)'),
|
|
94
|
+
outputLogs: Schema.boolean().default(true).description('输出详细日志'),
|
|
95
|
+
}).description('⑥ 权限与日志'),
|
|
96
|
+
|
|
97
|
+
// ---------------- 进阶(默认折叠) ----------------
|
|
98
|
+
Schema.object({
|
|
99
|
+
customWorkflowEnabled: Schema.boolean().default(false).description('使用自定义 ComfyUI 工作流 JSON'),
|
|
100
|
+
customWorkflowPath: Schema.string().default('').description('工作流 JSON 路径(相对 Koishi 运行目录,如 data/p-draw/workflows/anima-aesthetic-v1.1.json)'),
|
|
101
|
+
skipQualityPrefixForCustomWorkflow: Schema.boolean().default(true).description('启用自定义工作流时跳过质量前缀注入'),
|
|
102
|
+
customWorkflowOverrideParameters: Schema.boolean().default(false).description('用插件参数覆盖工作流内的采样参数'),
|
|
103
|
+
customWorkflowReloadOnChange: Schema.boolean().default(true).description('工作流文件变化时自动重载(无需重启)'),
|
|
104
|
+
positivePromptNodeId: Schema.string().default('').description('正面提示词节点 ID(留空自动识别;示例 6,以实际 JSON 为准)'),
|
|
105
|
+
negativePromptNodeId: Schema.string().default('').description('负面提示词节点 ID(留空自动识别;示例 7)'),
|
|
106
|
+
resolutionNodeId: Schema.string().default('').description('尺寸节点 ID(EmptyLatentImage,可留空;示例 5)'),
|
|
107
|
+
seedNodeId: Schema.string().default('').description('种子节点 ID(KSampler,可留空;示例 3)'),
|
|
108
|
+
stepsNodeId: Schema.string().default('').description('步数节点 ID(KSampler,可留空;示例 3)'),
|
|
109
|
+
}).description('⑦ 自定义工作流').collapse(),
|
|
110
|
+
|
|
111
|
+
Schema.object({
|
|
112
|
+
modelParams: Schema.dict(Schema.object({
|
|
113
|
+
samplerName: Schema.string().description('采样器'),
|
|
114
|
+
scheduler: Schema.string().description('调度器'),
|
|
115
|
+
steps: Schema.number().description('采样步数'),
|
|
116
|
+
cfg: Schema.number().description('CFG 强度'),
|
|
117
|
+
width: Schema.number().description('默认宽度'),
|
|
118
|
+
height: Schema.number().description('默认高度'),
|
|
119
|
+
}).description('该模型的参数覆盖')).default({}).description('按模型覆盖参数:key=模型文件名,value 只填要覆盖的字段。优先级:命令级 --steps/--cfg > 本节 > 全局配置'),
|
|
120
|
+
}).description('⑧ 模型独立参数覆盖').collapse(),
|
|
121
|
+
|
|
122
|
+
Schema.object({
|
|
123
|
+
promptOptimizeEnabled: Schema.boolean().default(false).description('启用自然语言优化(需配置下面的 LLM 接口)'),
|
|
124
|
+
llmBaseUrl: Schema.string().default('').description('LLM 接口地址(OpenAI 兼容,如 https://api.deepseek.com/v1)'),
|
|
125
|
+
llmApiKey: Schema.string().role('secret').default('').description('LLM API Key'),
|
|
126
|
+
llmModel: Schema.string().default('').description('LLM 模型名(留空则不优化)'),
|
|
127
|
+
llmMaxTokens: Schema.number().default(1000).description('LLM 输出上限'),
|
|
128
|
+
promptOptimizeTemplate: Schema.string().description('优化模板(支持 {theme} {search_block} {character_rule} 占位符)').default('你是为 Anima 图像生成模型编写正面提示词的 AI 画师。\n\n请根据用户的原始要求设计一幅完整、协调、具有视觉吸引力的画面,并将结果输出为英文 Danbooru-style tags。\n\n输出要求:\n- 只输出一行英文 tags,使用英文逗号分隔。\n- 不要输出解释、分析、标题、编号、Markdown、代码块或中文。\n- 不要输出 masterpiece、best quality、score 等质量前缀。\n- 不要输出画师 tags;质量词和画师组会由程序另行拼接。\n- 尽量使用模型容易理解的可见画面描述。\n- 保持用户明确指定的角色、主体、人数、关键服装、动作、表情和道具。\n- 除上述明确要求外,可以自由决定服装细节、姿态、构图、镜头、背景、环境、光影、色彩、氛围、前景和特效。\n- 以最终图像协调、精致、有表现力和好看为优先,不需要机械追求固定 Tag 数量。\n- 不要为了数量重复同义词;画面已经完整时即可停止。\n- 请自行解决明显冲突,直接输出你认为最适合生成最终画面的版本。\n\n角色和动态上下文:\n{character_rule}\n{search_block}\n\n用户原始要求:\n{theme}'),
|
|
129
|
+
}).description('⑨ 提示词优化 / LLM').collapse(),
|
|
130
|
+
|
|
131
|
+
Schema.object({
|
|
132
|
+
webSearchEnabled: Schema.boolean().default(false).description('启用联网搜索(指令里写「联网/搜索/查一下」触发)'),
|
|
133
|
+
tavilyApiKey: Schema.string().role('secret').default('').description('Tavily API Key(https://tavily.com)'),
|
|
134
|
+
webSearchMaxResults: Schema.number().default(5).description('搜索结果数量'),
|
|
135
|
+
webSearchDepth: Schema.string().default('basic').description('搜索深度(basic / advanced)'),
|
|
136
|
+
webSearchQueryTemplate: Schema.string().default('{prompt} 角色 外观 立绘 服装 配色 武器 官方图 official art character design outfit appearance wiki fandom').description('搜索词模板({prompt} 代表用户需求)'),
|
|
137
|
+
}).description('⑩ 联网搜索').collapse(),
|
|
138
|
+
|
|
139
|
+
Schema.object({
|
|
140
|
+
multiVerifyEnabled: Schema.boolean().default(true).description('多人图生成后启用视觉校验'),
|
|
141
|
+
multiVerifyPassScore: Schema.number().default(6).description('校验合格分数(0-10)'),
|
|
142
|
+
multiCandidateCount: Schema.number().default(2).description('候选采样数量(最多重试 候选数-1 次)'),
|
|
143
|
+
multiSendDegradedCandidate: Schema.boolean().default(true).description('全部候选不达标时仍发送最优候选'),
|
|
144
|
+
verifyLlmBaseUrl: Schema.string().default('').description('视觉校验接口地址(OpenAI 兼容;留空跳过校验)'),
|
|
145
|
+
verifyLlmApiKey: Schema.string().role('secret').default('').description('视觉校验 API Key'),
|
|
146
|
+
verifyLlmModel: Schema.string().default('').description('视觉校验模型名(需支持图片输入,如 qwen-vl)'),
|
|
147
|
+
}).description('⑪ 多人视觉校验').collapse(),
|
|
148
|
+
|
|
149
|
+
Schema.object({
|
|
150
|
+
workflow: Schema.string().default('anima_t2i').description('旧版工作流标识,仅用于状态/诊断显示,内置工作流固定 anima_t2i'),
|
|
151
|
+
}).description('⑫ 兼容项(旧版,可忽略)').collapse(),
|
|
152
|
+
]).i18n({
|
|
128
153
|
'zh-CN': zhCN,
|
|
129
154
|
})
|
|
130
155
|
|
|
@@ -132,7 +157,7 @@ exports.Config = Schema.object({
|
|
|
132
157
|
// 纯函数库已拆分到 lib/(解析 / tag 清洗 / 工作流 / Comfy 等待 / 多人规划 / HTTP 客户端)
|
|
133
158
|
// ------------------------------------------------------------------
|
|
134
159
|
const {
|
|
135
|
-
normalizeBaseUrl, escapeRe, parseGenerationSize, parseBatchCount, parseSeed,
|
|
160
|
+
normalizeBaseUrl, escapeRe, parseGenerationSize, parseBatchCount, parseSeed, parseStepsCfg,
|
|
136
161
|
stripRawPrefix, splitPositiveNegativePrompt, parseNameTags, parsePresetList, mergeTagText,
|
|
137
162
|
} = require('./lib/parse')
|
|
138
163
|
const {
|
|
@@ -1486,9 +1511,16 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1486
1511
|
|
|
1487
1512
|
// 批量张数解析(x3 / 3张 / --数量 3 等)
|
|
1488
1513
|
const parsedBatch = parseBatchCount(parsedSize.prompt, cfg.batchMax)
|
|
1489
|
-
|
|
1514
|
+
// 采样参数覆盖(--steps 40 / --cfg 3.5),并从描述中剥离,避免进入 LLM 规划
|
|
1515
|
+
const parsedTuning = parseStepsCfg(parsedBatch.prompt)
|
|
1516
|
+
const text = parsedTuning.prompt
|
|
1490
1517
|
if (!text) return session.text('.multi-usage')
|
|
1491
1518
|
const count = parsedBatch.count
|
|
1519
|
+
const tuningOverrides = Object.assign(
|
|
1520
|
+
{},
|
|
1521
|
+
parsedTuning.steps != null ? { steps: parsedTuning.steps } : {},
|
|
1522
|
+
parsedTuning.cfg != null ? { cfg: parsedTuning.cfg } : {},
|
|
1523
|
+
)
|
|
1492
1524
|
|
|
1493
1525
|
// P 点校验(按总价 = 张数 × 单价)
|
|
1494
1526
|
const pcheck = await precheckPoints(session, USERID, isAdmin, count * price)
|
|
@@ -1533,7 +1565,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1533
1565
|
}
|
|
1534
1566
|
|
|
1535
1567
|
// 队列:预排队全部任务(先查容量再入队,占满整体退回总价)
|
|
1536
|
-
const queued = await enqueueBatch(count, (i) => runComfyGenerate(finalPrompt, size, { negativePrompt: multiNegative, unet }), { USERID, isAdmin, totalPrice: count * price })
|
|
1568
|
+
const queued = await enqueueBatch(count, (i) => runComfyGenerate(finalPrompt, size, Object.assign({ negativePrompt: multiNegative, unet }, tuningOverrides)), { USERID, isAdmin, totalPrice: count * price })
|
|
1537
1569
|
if (!queued.ok) return queued.message
|
|
1538
1570
|
const queuedTasks = queued.tasks
|
|
1539
1571
|
const firstPosition = queued.firstPosition
|
|
@@ -1551,7 +1583,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1551
1583
|
if (cfg.queueEnabled) {
|
|
1552
1584
|
try { result = await queuedTasks[i] } catch (e) { result = { ok: false, message: `生成失败:${e.message}` } }
|
|
1553
1585
|
} else {
|
|
1554
|
-
try { result = await runComfyGenerate(finalPrompt, size, { negativePrompt: multiNegative, unet }) } catch (e) { result = { ok: false, message: `生成失败:${e.message}` } }
|
|
1586
|
+
try { result = await runComfyGenerate(finalPrompt, size, Object.assign({ negativePrompt: multiNegative, unet }, tuningOverrides)) } catch (e) { result = { ok: false, message: `生成失败:${e.message}` } }
|
|
1555
1587
|
}
|
|
1556
1588
|
if (!result.ok || !result.outputs || !result.outputs.length) return result
|
|
1557
1589
|
if (!cfg.multiVerifyEnabled) {
|
|
@@ -1939,9 +1971,20 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1939
1971
|
const parsedBatch = parseBatchCount(parsedSize.prompt, cfg.batchMax)
|
|
1940
1972
|
// 固定种子解析(--seed:xxx / --seed xxx / --seed=xxx),并从提示词中剥离
|
|
1941
1973
|
const parsedSeed = parseSeed(parsedBatch.prompt)
|
|
1942
|
-
|
|
1974
|
+
// 采样参数覆盖(--steps 40 / --cfg 3.5),并从提示词中剥离
|
|
1975
|
+
const parsedTuning = parseStepsCfg(parsedSeed.prompt)
|
|
1976
|
+
const text = parsedTuning.prompt
|
|
1943
1977
|
const seed = parsedSeed.seed
|
|
1944
1978
|
const count = parsedBatch.count
|
|
1979
|
+
// 命令级参数优先于 modelParams 与全局配置(见 runComfyGenerate)
|
|
1980
|
+
const tuningOverrides = Object.assign(
|
|
1981
|
+
{},
|
|
1982
|
+
parsedTuning.steps != null ? { steps: parsedTuning.steps } : {},
|
|
1983
|
+
parsedTuning.cfg != null ? { cfg: parsedTuning.cfg } : {},
|
|
1984
|
+
)
|
|
1985
|
+
if (cfg.outputLogs && (parsedTuning.steps != null || parsedTuning.cfg != null)) {
|
|
1986
|
+
logger.info(`[p-draw] 命令级参数覆盖:steps=${parsedTuning.steps ?? '-'} cfg=${parsedTuning.cfg ?? '-'}`)
|
|
1987
|
+
}
|
|
1945
1988
|
|
|
1946
1989
|
// P 点校验(按总价 = 张数 × 单价)
|
|
1947
1990
|
// P 点校验(按总价 = 张数 × 单价)
|
|
@@ -2042,6 +2085,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
2042
2085
|
// 用户手写了 negative: 区块时,默认负面词仍保留;用户 tag 只补充未出现的部分。
|
|
2043
2086
|
const generationOverrides = Object.assign(
|
|
2044
2087
|
{ unet, seed },
|
|
2088
|
+
tuningOverrides,
|
|
2045
2089
|
userNegativePrompt ? { negativePrompt: mergeNegativePrompts(cfg.negativePrompt, userNegativePrompt) } : {},
|
|
2046
2090
|
)
|
|
2047
2091
|
|
package/lib/i18n.js
CHANGED
|
@@ -70,7 +70,7 @@ const zhCN = {
|
|
|
70
70
|
description: '连接本地 ComfyUI 生图,消耗 P 点',
|
|
71
71
|
messages: {
|
|
72
72
|
'not-permitted': 'ComfyUI 助手已关闭,或当前用户没有使用权限。',
|
|
73
|
-
usage: 'p-draw 帮助(本指令名可自行更换,如 /anm):\n\n【生成】\n p-draw <描述>\n 可加 --seed 数字、x3 / 3张、竖图 / 横图 / 方图\n 无优化 <tags> 可直接使用手写 tags\n\n【多人生成】\n p-draw 多人 <描述>(2-4 人画面,依赖 LLM 规划)\n\n【提示词优化】\n 配置 LLM 后可将自然语言转为 Danbooru tags;普通用户可使用提示词优化券\n\n【画师组】\n 创建 / 追加 / 切换 / 查看 / 删除画师组\n\n【固定角色】\n 添加角色 名称=tags\n\n【模型】\n p-draw 模型(查看) / p-draw 模型 <名称>(切换)/ p-draw 模型 默认(重置)\n\n【状态】\n p-draw 状态\n\n生成图片以合并转发发送,并附对应的 Positive / Negative 提示词;扣费提醒单独引用原指令。',
|
|
73
|
+
usage: 'p-draw 帮助(本指令名可自行更换,如 /anm):\n\n【生成】\n p-draw <描述>\n 可加 --seed 数字、x3 / 3张、竖图 / 横图 / 方图\n 临时覆盖采样参数:--steps 40 / --cfg 3.5\n 无优化 <tags> 可直接使用手写 tags\n\n【多人生成】\n p-draw 多人 <描述>(2-4 人画面,依赖 LLM 规划)\n\n【提示词优化】\n 配置 LLM 后可将自然语言转为 Danbooru tags;普通用户可使用提示词优化券\n\n【画师组】\n 创建 / 追加 / 切换 / 查看 / 删除画师组\n\n【固定角色】\n 添加角色 名称=tags\n\n【模型】\n p-draw 模型(查看) / p-draw 模型 <名称>(切换)/ p-draw 模型 默认(重置)\n\n【状态】\n p-draw 状态\n\n生成图片以合并转发发送,并附对应的 Positive / Negative 提示词;扣费提醒单独引用原指令。',
|
|
74
74
|
'account-notExists': '君现在还没有 p 点,请先签到哦',
|
|
75
75
|
'no-enough-p': '君的 p 点不够 {0}p 哦,先去签个到吧qwq',
|
|
76
76
|
'no-prompt': '请提供画面描述,例如:p-draw 一个女孩,白色裙子',
|
package/lib/parse.js
CHANGED
|
@@ -152,6 +152,45 @@ function parseSeed(text) {
|
|
|
152
152
|
return { seed, prompt: cleaned }
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
// 采样参数覆盖:--steps 40 / --步数 40 / --cfg 3.5 / --强度 3.5
|
|
156
|
+
// 从提示词里剥离并返回 { steps, cfg, prompt };缺失或越界的值返回 null(保持默认)。
|
|
157
|
+
const STEPS_LIMIT = { min: 1, max: 150 }
|
|
158
|
+
const CFG_LIMIT = { min: 0, max: 30 }
|
|
159
|
+
|
|
160
|
+
const STEPS_PATTERN = /(?<!\S)--(?:steps|步数)\s*(?:=|=|:|:)?\s*(\d+)/i
|
|
161
|
+
const CFG_PATTERN = /(?<!\S)--(?:cfg|强度)\s*(?:=|=|:|:)?\s*(\d+(?:\.\d+)?)/i
|
|
162
|
+
|
|
163
|
+
// 与 parseSeed 一致的剥离清理:去掉 token 后收拢多余分隔符与空白
|
|
164
|
+
function stripMatchedToken(prompt, match) {
|
|
165
|
+
return (prompt.slice(0, match.index) + ' ' + prompt.slice(match.index + match[0].length))
|
|
166
|
+
.trim()
|
|
167
|
+
.replace(/^[\s,,;;::]+|[\s,,;;::]+$/g, '')
|
|
168
|
+
.replace(/([,,;;])\s*[,,;;]+/g, '$1')
|
|
169
|
+
.replace(/\s+/g, ' ')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function parseStepsCfg(text) {
|
|
173
|
+
let prompt = String(text || '').trim()
|
|
174
|
+
let steps = null
|
|
175
|
+
let cfg = null
|
|
176
|
+
|
|
177
|
+
const stepsMatch = prompt.match(STEPS_PATTERN)
|
|
178
|
+
if (stepsMatch) {
|
|
179
|
+
const value = parseInt(stepsMatch[1], 10)
|
|
180
|
+
prompt = stripMatchedToken(prompt, stepsMatch)
|
|
181
|
+
if (Number.isFinite(value) && value >= STEPS_LIMIT.min) steps = Math.min(value, STEPS_LIMIT.max)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const cfgMatch = prompt.match(CFG_PATTERN)
|
|
185
|
+
if (cfgMatch) {
|
|
186
|
+
const value = Number(cfgMatch[1])
|
|
187
|
+
prompt = stripMatchedToken(prompt, cfgMatch)
|
|
188
|
+
if (Number.isFinite(value) && value >= CFG_LIMIT.min) cfg = Math.min(value, CFG_LIMIT.max)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return { steps, cfg, prompt }
|
|
192
|
+
}
|
|
193
|
+
|
|
155
194
|
// ------------------------------------------------------------------
|
|
156
195
|
// 提示词辅助(移植自 anima prompt_presets)
|
|
157
196
|
// ------------------------------------------------------------------
|
|
@@ -257,6 +296,12 @@ module.exports = {
|
|
|
257
296
|
cnNumValue,
|
|
258
297
|
parseBatchCount,
|
|
259
298
|
parseSeed,
|
|
299
|
+
STEPS_LIMIT,
|
|
300
|
+
CFG_LIMIT,
|
|
301
|
+
STEPS_PATTERN,
|
|
302
|
+
CFG_PATTERN,
|
|
303
|
+
stripMatchedToken,
|
|
304
|
+
parseStepsCfg,
|
|
260
305
|
RAW_PREFIXES,
|
|
261
306
|
stripRawPrefix,
|
|
262
307
|
splitPositiveNegativePrompt,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -11,6 +11,7 @@ p点-绘图插件,连接本地 ComfyUI 生图,参考 AstrBot 的 [anima 绘
|
|
|
11
11
|
- 联网搜索:描述中带 `联网`/`搜索`/`查一下` 等词时自动补充角色设定(需 Tavily Key)。
|
|
12
12
|
- 原样 tags 模式(`无优化` 前缀)。
|
|
13
13
|
- 尺寸选择:`竖图` `横图` `方图` `长竖图` `宽屏`,或 `1024x1536:描述` / `--尺寸 1216x832`。
|
|
14
|
+
- 采样参数临时覆盖(可选):`画图 少女 --cfg 3.5 --steps 40`(也可写 `--强度 3.5` / `--步数 40`)。优先级:命令级 > `modelParams` > 全局配置;参数会从提示词里剥离,不会混进 tags。
|
|
14
15
|
- 画师组管理(创建 / 追加 / 切换 / 查看 / 删除)。
|
|
15
16
|
- 固定角色(`添加角色 名称=tags`,可用 `查看角色` / `删除角色 名称` 管理)。
|
|
16
17
|
- **用户自选模型**:`p-draw 模型` 查看当前与可用模型(自动读取 ComfyUI 的 UNET 和 Animagine checkpoint),`p-draw 模型 <名称>` 切换(支持模糊匹配,如 `anima-aesthetic`),`p-draw 模型 默认` 恢复默认。偏好按用户保存(`p_draw_config.user_models`),单人和多人生成都会生效;未自选时用 `unetName` 默认模型。自定义工作流(`customWorkflowEnabled`)不参与模型切换。
|
|
@@ -48,6 +49,7 @@ plugins:
|
|
|
48
49
|
画图 无优化 masterpiece, best quality, 1girl, solo, white dress, simple background
|
|
49
50
|
画图 竖图:狐莉站在梨花树下
|
|
50
51
|
画图 1024x1536:少女站在河岸
|
|
52
|
+
画图 少女站在河岸 --cfg 3.5 --steps 40
|
|
51
53
|
画图 创建画师组 千代风格=@artist_a, @artist_b,
|
|
52
54
|
画图 切换画师组 千代风格
|
|
53
55
|
画图 添加角色 狐莉=1girl, solo, fox girl
|
|
@@ -62,35 +64,117 @@ plugins:
|
|
|
62
64
|
|
|
63
65
|
## 配置说明
|
|
64
66
|
|
|
67
|
+
控制台里配置分成 **12 个可折叠小节**:①–⑥ 常用项默认展开,⑦–⑫ 进阶项默认折叠。`koishi.yml` 里的键仍然是**扁平**的(见文末示例),分组只影响界面显示,旧配置无需迁移。
|
|
68
|
+
|
|
69
|
+
### ① ComfyUI 连接
|
|
70
|
+
|
|
65
71
|
| 项 | 说明 |
|
|
66
72
|
|----|------|
|
|
67
73
|
| `comfyuiBaseUrl` | ComfyUI API 地址(默认 `http://127.0.0.1:8188`) |
|
|
68
|
-
| `
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
|
73
|
-
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
74
|
+
| `timeout` / `pollInterval` | 单次生成超时(秒,默认 300)、状态查询间隔(秒,默认 2) |
|
|
75
|
+
|
|
76
|
+
### ② 模型与采样参数
|
|
77
|
+
|
|
78
|
+
| 项 | 说明 |
|
|
79
|
+
|----|------|
|
|
80
|
+
| `unetName` / `clipName` / `vaeName` | 模型文件名,需与 ComfyUI 下拉框中的文件名完全一致 |
|
|
81
|
+
| `useGgufUnet` | `auto`(按后缀判断,默认)/ `true`(强制 `UnetLoaderGGUF`,需装 ComfyUI-GGUF)/ `false`(强制 `UNETLoader`) |
|
|
76
82
|
| `width` / `height` / `allowedSizes` | 默认尺寸与可用尺寸列表 |
|
|
77
|
-
| `steps` / `cfg` / `samplerName` / `scheduler` |
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
|
82
|
-
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
|
91
|
-
|
|
83
|
+
| `steps` / `cfg` / `samplerName` / `scheduler` | 采样参数(Aesthetic 1.1 推荐 `30 / 4.0 / er_sde / simple`) |
|
|
84
|
+
|
|
85
|
+
### ③ 提示词与画师
|
|
86
|
+
|
|
87
|
+
| 项 | 说明 |
|
|
88
|
+
|----|------|
|
|
89
|
+
| `qualityPrefix` / `negativePrompt` | 质量词前缀与负面词。默认 `qualityPrefix` 为空(Aesthetic 1.1 不需要质量标签),`negativePrompt` 为 Aesthetic 推荐值;从 Base 模型迁移时再把前缀填回 `masterpiece, best quality, score_7` |
|
|
90
|
+
| `styleTags` / `defaultArtistTags` | 画风 tags、备用画师 tags |
|
|
91
|
+
| `activeArtistPreset` / `artistPresets` | 启用的画师组名称与画师组列表 |
|
|
92
|
+
| `fixedCharacters` | 固定角色(仅兼容旧配置,运行时以数据库为准) |
|
|
93
|
+
|
|
94
|
+
### ④ 队列与批量
|
|
95
|
+
|
|
96
|
+
| 项 | 说明 |
|
|
97
|
+
|----|------|
|
|
98
|
+
| `queueEnabled` / `queueMaxRequests` | 生成队列开关与上限(0 表示不限制) |
|
|
99
|
+
| `batchMax` | 单次指令最多生成的张数(`x3` / `3张` / `--数量 3`),默认 4 |
|
|
100
|
+
|
|
101
|
+
### ⑤ P 点与优化券
|
|
102
|
+
|
|
103
|
+
| 项 | 说明 |
|
|
104
|
+
|----|------|
|
|
105
|
+
| `price` / `multiPrice` | 单张 / 多人单张消耗的 P 点 |
|
|
106
|
+
| `couponPrice` / `couponAskTimeout` | 提示词优化券单价(默认 3000,可被 `data/p-shop.json` 覆盖)与确认等待时间(秒) |
|
|
107
|
+
| `adminUsers` | 免 P 点管理员用户 ID |
|
|
108
|
+
|
|
109
|
+
### ⑥ 权限与日志
|
|
110
|
+
|
|
111
|
+
| 项 | 说明 |
|
|
112
|
+
|----|------|
|
|
113
|
+
| `adminOnly` | 仅管理员可用 |
|
|
114
|
+
| `allowedUserIds` / `blockedUserIds` | 用户白名单 / 黑名单(黑名单优先) |
|
|
115
|
+
| `allowedGroupIds` / `blockedGroupIds` | 群白名单 / 黑名单(黑名单优先) |
|
|
92
116
|
| `outputLogs` | 是否输出详细日志 |
|
|
93
117
|
|
|
118
|
+
### ⑦ 自定义工作流(折叠)
|
|
119
|
+
|
|
120
|
+
| 项 | 说明 |
|
|
121
|
+
|----|------|
|
|
122
|
+
| `customWorkflowEnabled` / `customWorkflowPath` | 启用自定义工作流 JSON;路径相对 Koishi 运行目录解析 |
|
|
123
|
+
| `skipQualityPrefixForCustomWorkflow` | 启用自定义工作流时跳过质量前缀注入(默认 `true`) |
|
|
124
|
+
| `customWorkflowOverrideParameters` | 用插件参数覆盖工作流内的采样参数 |
|
|
125
|
+
| `customWorkflowReloadOnChange` | 工作流文件变化时自动重载,无需重启(默认 `true`) |
|
|
126
|
+
| `positivePromptNodeId` / `negativePromptNodeId` | 正/负面提示词节点 ID;留空自动识别 |
|
|
127
|
+
| `resolutionNodeId` / `seedNodeId` / `stepsNodeId` | 尺寸 / 种子 / 步数节点 ID;可留空(留空则按节点类型覆盖) |
|
|
128
|
+
|
|
129
|
+
### ⑧ 模型独立参数覆盖(折叠)
|
|
130
|
+
|
|
131
|
+
| 项 | 说明 |
|
|
132
|
+
|----|------|
|
|
133
|
+
| `modelParams` | 字典:`key`=模型文件名,`value` 只填要覆盖的 `samplerName` / `scheduler` / `steps` / `cfg` / `width` / `height`。匹配不区分大小写与 `-` `_`。优先级:命令级 `--steps`/`--cfg` > 本节 > 全局配置 |
|
|
134
|
+
|
|
135
|
+
### ⑨ 提示词优化 / LLM(折叠)
|
|
136
|
+
|
|
137
|
+
| 项 | 说明 |
|
|
138
|
+
|----|------|
|
|
139
|
+
| `promptOptimizeEnabled` / `llmBaseUrl` / `llmApiKey` / `llmModel` | 自然语言优化(OpenAI 兼容接口) |
|
|
140
|
+
| `llmMaxTokens` | LLM 输出上限 |
|
|
141
|
+
| `promptOptimizeTemplate` | 优化模板(支持 `{theme}` `{search_block}` `{character_rule}` 占位符) |
|
|
142
|
+
|
|
143
|
+
### ⑩ 联网搜索(折叠)
|
|
144
|
+
|
|
145
|
+
| 项 | 说明 |
|
|
146
|
+
|----|------|
|
|
147
|
+
| `webSearchEnabled` / `tavilyApiKey` | 联网搜索开关与 Tavily Key |
|
|
148
|
+
| `webSearchMaxResults` / `webSearchDepth` / `webSearchQueryTemplate` | 结果数量、搜索深度、搜索词模板 |
|
|
149
|
+
|
|
150
|
+
### ⑪ 多人视觉校验(折叠)
|
|
151
|
+
|
|
152
|
+
| 项 | 说明 |
|
|
153
|
+
|----|------|
|
|
154
|
+
| `multiVerifyEnabled` / `multiVerifyPassScore` | 校验开关与合格分数(0-10) |
|
|
155
|
+
| `multiCandidateCount` / `multiSendDegradedCandidate` | 候选采样数与全部不达标时是否仍发送最优候选 |
|
|
156
|
+
| `verifyLlmBaseUrl` / `verifyLlmApiKey` / `verifyLlmModel` | 视觉模型(需支持图片输入;留空则跳过校验) |
|
|
157
|
+
|
|
158
|
+
### ⑫ 兼容项(折叠)
|
|
159
|
+
|
|
160
|
+
| 项 | 说明 |
|
|
161
|
+
|----|------|
|
|
162
|
+
| `workflow` | 旧版工作流标识,仅用于状态/诊断显示,内置工作流固定 `anima_t2i` |
|
|
163
|
+
|
|
164
|
+
`koishi.yml` 里仍是扁平写法(分组不影响它):
|
|
165
|
+
|
|
166
|
+
```yaml
|
|
167
|
+
p-draw:0z81el:
|
|
168
|
+
comfyuiBaseUrl: http://127.0.0.1:8188
|
|
169
|
+
unetName: anima-aesthetic-v1.1.safetensors
|
|
170
|
+
qualityPrefix: ''
|
|
171
|
+
cfg: 4.0
|
|
172
|
+
steps: 30
|
|
173
|
+
# 进阶项同样扁平,例如:
|
|
174
|
+
# customWorkflowEnabled: true
|
|
175
|
+
# customWorkflowPath: data/p-draw/workflows/anima-aesthetic-v1.1.json
|
|
176
|
+
```
|
|
177
|
+
|
|
94
178
|
## 工作流对接:Anima Aesthetic 1.1
|
|
95
179
|
|
|
96
180
|
### 1. 模型文件放置
|
|
@@ -186,6 +270,7 @@ p-draw:
|
|
|
186
270
|
- 批量张数按「张数 × 单价」**一次性扣足总价**,余额不足则整单不生成;单张失败只退该张。
|
|
187
271
|
- 生成失败会自动退回 P 点。
|
|
188
272
|
- 固定种子 `--seed 数字`(支持 `--seed:` `--seed=` `--seed=` 形式)在单张和批量生成中都可用,且会从提示词中自动剥离,不会混进 tags。
|
|
273
|
+
- 采样参数 `--steps 40` / `--cfg 3.5`(兼容 `--步数` / `--强度`,支持 `=` `:` 形式)同样会从提示词中剥离,只覆盖当次生成,不改配置。取值范围:步数 1–150,CFG 0–30,超出会被截断。
|
|
189
274
|
- 多人指令的视觉校验需要单独配置视觉模型(`verifyLlm*`),未配置时会跳过校验直接发送。
|
|
190
275
|
- **提示词优化券**:当全局 `promptOptimizeEnabled` 关闭时,普通用户生图会**交互式询问**是否使用券(记录在 `p_system.llmToken`):
|
|
191
276
|
- 有券 → 询问是否使用;确认后消耗券并 LLM 优化,**拒绝则取消本次生图**(不扣 P);
|