2024-12-09 14:34:56 +08:00
2024-12-09 14:34:56 +08:00
2024-12-09 14:34:56 +08:00
2024-12-05 01:12:34 +08:00
2024-12-05 01:12:34 +08:00
2024-12-05 01:12:34 +08:00

ComfyUI 字符串自定义节点

ComfyUI的字符串相关的自定义节点,提供使用f-string语法的字符串格式化功能。

image

直接拖入ComfyUI即可使用

安装方法

  1. 将此仓库克隆到你的 ComfyUI/custom_nodes 目录下:
cd custom_nodes
git clone https://github.com/liuqianhonga/ComfyUI-String-Helper.git
  1. 重启 ComfyUI

String Formatter 节点使用说明

字符串格式化节点允许你使用Python的f-string语法来格式化字符串。你可以在模板字符串中引用最多10个输入参数(arg1到arg10)且自由定制模板。

节点参数

  • template (必需):使用f-string语法的模板字符串
  • arg1 - arg10 (可选):可在模板中引用的输入参数

使用示例

  1. 基础文本格式化:
arg1: "小明"
arg2: "ComfyUI"

模板: "你好 {arg1},欢迎来到 {arg2}!"
输出: "你好 小明,欢迎来到 ComfyUI!"
  1. 数字使用示例:
arg1: 10
arg2: 20
arg3: 30

模板: "计算结果: {arg1} + {arg2} = {arg3}"
输出: "计算结果: 10 + 20 = 30"
  1. 对象使用示例:
arg1: {"名称": "模型_v1", "类型": "checkpoint"}

模板: "模型信息: {arg1}"
输出: "模型信息: {'名称': '模型_v1', '类型': 'checkpoint'}"

注意事项

  • 未提供的参数(None值)将被忽略
  • 节点支持任何类型的输入(字符串、数字、列表、字典等)
  • 同一个参数可以在模板中多次使用
  • 支持Python f-string的所有格式化特性

错误处理

如果模板或格式化过程中出现错误,节点将返回错误信息字符串:

当引用了未提供的参数时:
模板: "你好 {arg1},{arg2}"
arg1: "世界"
输出: "Format Error: name 'arg2' is not defined"
S
Description
No description provided
Readme MIT
824 KiB
Languages
Python 90.2%
JavaScript 9.8%