什么是通配符?
通配符是一个在每次队列(queue)执行时,随机替换提示词一部分的功能,用来给生成结果增加变化。
例如写成 photo of {red|yellow|blue} flower,执行时会从 red / yellow / blue 里随机选一个。
一次性大量出图时,如果一直使用同一条提示词会比较单调,所以可以用这个方式让结果更有变化。
每次队列执行使用随机提示词生成图片
ComfyUI 的文本输入框(例如 CLIP Text Encode)默认支持 {a|b|c} 这种通配符写法。
{
"id": "8b9f7796-0873-4025-be3c-0f997f67f866",
"revision": 0,
"last_node_id": 10,
"last_link_id": 10,
"nodes": [
{
"id": 9,
"type": "SaveImage",
"pos": [
1451,
189
],
"size": [
354.2876035004722,
433.23967321788405
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 9
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.33"
},
"widgets_values": [
"ComfyUI"
]
},
{
"id": 7,
"type": "CLIPTextEncode",
"pos": [
416.1970166015625,
392.37848510742185
],
"size": [
410.75801513671877,
158.82607910156253
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 5
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"slot_index": 0,
"links": [
6
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.33",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"text, watermark"
]
},
{
"id": 5,
"type": "EmptyLatentImage",
"pos": [
582.1350317382813,
606.5799999999999
],
"size": [
244.81999999999994,
106
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"slot_index": 0,
"links": [
2
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.33",
"Node name for S&R": "EmptyLatentImage"
},
"widgets_values": [
512,
512,
1
]
},
{
"id": 6,
"type": "CLIPTextEncode",
"pos": [
415,
186
],
"size": [
411.95503173828126,
151.0030493164063
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 3
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"slot_index": 0,
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.33",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"photo of {red|yellow|blue} flower"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 10,
"type": "VAELoader",
"pos": [
896.9256198347109,
69.4815990090115
],
"size": [
281.0743801652891,
58
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "VAE",
"type": "VAE",
"links": [
10
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "VAELoader"
},
"widgets_values": [
"vae-ft-mse-840000-ema-pruned.safetensors"
]
},
{
"id": 4,
"type": "CheckpointLoaderSimple",
"pos": [
38.10000000000001,
363.8900000000004
],
"size": [
315,
98
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"slot_index": 0,
"links": [
1
]
},
{
"name": "CLIP",
"type": "CLIP",
"slot_index": 1,
"links": [
3,
5
]
},
{
"name": "VAE",
"type": "VAE",
"slot_index": 2,
"links": []
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.33",
"Node name for S&R": "CheckpointLoaderSimple"
},
"widgets_values": [
"📷-v1.x\\real-dream-15.safetensors"
]
},
{
"id": 8,
"type": "VAEDecode",
"pos": [
1209,
188
],
"size": [
215.32399999999984,
46
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": 7
},
{
"name": "vae",
"type": "VAE",
"link": 10
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"slot_index": 0,
"links": [
9
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.33",
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
},
{
"id": 3,
"type": "KSampler",
"pos": [
863,
186
],
"size": [
315,
262
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 1
},
{
"name": "positive",
"type": "CONDITIONING",
"link": 4
},
{
"name": "negative",
"type": "CONDITIONING",
"link": 6
},
{
"name": "latent_image",
"type": "LATENT",
"link": 2
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"slot_index": 0,
"links": [
7
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.33",
"Node name for S&R": "KSampler"
},
"widgets_values": [
1234,
"fixed",
20,
8,
"euler",
"normal",
1
]
}
],
"links": [
[
1,
4,
0,
3,
0,
"MODEL"
],
[
2,
5,
0,
3,
3,
"LATENT"
],
[
3,
4,
1,
6,
0,
"CLIP"
],
[
4,
6,
0,
3,
1,
"CONDITIONING"
],
[
5,
4,
1,
7,
0,
"CLIP"
],
[
6,
7,
0,
3,
2,
"CONDITIONING"
],
[
7,
3,
0,
8,
0,
"LATENT"
],
[
9,
8,
0,
9,
0,
"IMAGE"
],
[
10,
10,
0,
8,
1,
"VAE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.7513148009015777,
"offset": [
440.206500000001,
417.55230099098833
]
},
"frontendVersion": "1.38.13",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
-
photo of {red|yellow|blue} flower- 会从
{}内的候选里选 1 个并展开到提示词中 - 也就是说,可能变成
photo of red flower,也可能是photo of blue flower
- 会从
Impact-Pack
默认可用的只是最基础的通配符形式。
如果你想做通配符嵌套、调整各词出现概率,或者从文本文件读取候选,最常见的做法是使用 Impact-Pack。
自定义节点
ImpactWildcardProcessor / Encode

{
"id": "f8094695-2eee-48d5-b2fc-4bc33a45fd26",
"revision": 0,
"last_node_id": 5,
"last_link_id": 2,
"nodes": [
{
"id": 2,
"type": "PreviewAny",
"pos": [
1683.9816091137036,
258.08768112764005
],
"size": [
306.70646627156475,
161.52284878372387
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 1
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.12.3",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 5,
"type": "ImpactWildcardEncode",
"pos": [
1223.0890556151678,
584.103729949037
],
"size": [
400,
322
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": null
},
{
"name": "clip",
"type": "CLIP",
"link": null
}
],
"outputs": [
{
"name": "model",
"type": "MODEL",
"links": null
},
{
"name": "clip",
"type": "CLIP",
"links": null
},
{
"name": "conditioning",
"type": "CONDITIONING",
"links": null
},
{
"name": "populated_text",
"type": "STRING",
"links": []
}
],
"properties": {
"cnr_id": "comfyui-impact-pack",
"ver": "6a517ebe06fea2b74fc41b3bd089c0d7173eeced",
"Node name for S&R": "ImpactWildcardEncode"
},
"widgets_values": [
"photo of {red|yellow|blue} flower",
"photo of red flower",
"populate",
"Select the LoRA to add to the text",
"Select Wildcard 🟢 Full Cache",
634019359798268,
"randomize"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 1,
"type": "ImpactWildcardProcessor",
"pos": [
1223.0890556151678,
258.08768112764005
],
"size": [
400,
238
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "processed text",
"type": "STRING",
"links": [
1
]
}
],
"properties": {
"cnr_id": "comfyui-impact-pack",
"ver": "6a517ebe06fea2b74fc41b3bd089c0d7173eeced",
"Node name for S&R": "ImpactWildcardProcessor"
},
"widgets_values": [
"photo of {2$$ and $$red|blue|yellow} flower",
"photo of red and blue flower",
"populate",
198090245179286,
"randomize",
"Select Wildcard 🟢 Full Cache"
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
1,
1,
0,
2,
0,
"STRING"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.9229599817706501,
"offset": [
-855.4718188134771,
93.27749675896803
]
},
"frontendVersion": "1.38.13",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
- 上方输入通配符文本
- 下方会显示展开后的文本
ImpactWildcardEncode 在此基础上还可以把 LoRA 作为通配符切换。
通配符语法(Impact-Pack)
dynamic prompts
最基础的写法是在 {} 里列出候选项。
-
{a|b|c}- 用
|分隔,随机选 1 个
- 用
-
{a|{1|2|3}|c}- 支持嵌套
-
{5::red|4::green|7::blue|black}- 在项目前加
n::可以设置权重 - 数字越大越容易被选中(最终会按总和归一化)
- 在项目前加
读取文本文件
你也可以单独准备词表文件,把它当作通配符源来调用。
-
- 放置位置
custom_nodes/ComfyUI-Impact-Pack/custom_wildcards
-
- 写法
-
例:
color.txtred blue yellow
-
- 调用方式
- 写
__color__时,会从文本文件随机选取 1 行 __color__ hair会展开成red hair/blue hair/yellow hair这类结果
-
也支持子文件夹
- 如果放在
custom_wildcards/obj/color.txt,则写成__obj/color__
- 如果放在
$$(多选)
$$ 用于从候选中选多个,并把它们作为一段字符串返回。
-
{n$$red|blue|yellow}- 从
red/blue/yellow中选择n个 - 例:
{2$$red|blue|yellow}->red blue/blue yellow
- 从
-
{n1-n2$$red|blue|yellow}- 选择
n1到n2个(数量本身也是随机) - 例:
{1-3$$red|blue|yellow}可能是red,也可能是red blue yellow
- 选择
-
{2$$ and $$red|blue|yellow}- 可以指定连接分隔符
- 例:
{2$$ and $$red|blue|yellow}->red and yellow/blue and red