Files
2026-01-05 11:29:28 -06:00

47 lines
1.5 KiB
Python

# AI Disclosure: Code comments were generated with AI but manually checked for correctness.
class SimpleFStringNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"template": ("STRING", {
"multiline": True,
"default": "The value of x is {x}"
}),
},
# We leave "optional" empty.
# The JS will force new inputs into the node, and ComfyUI
# will pass them to our function automatically.
"optional": {}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("formatted_string",)
FUNCTION = "format_inputs"
CATEGORY = "DLWW/Text"
# We use **kwargs to catch all the dynamic inputs created in the UI
def format_inputs(self, template, **kwargs):
clean_values = {}
for key, val in kwargs.items():
if val is None:
clean_values[key] = "None"
elif hasattr(val, 'shape'):
clean_values[key] = f"Tensor {val.shape}"
else:
clean_values[key] = str(val)
try:
result = template.format(**clean_values)
except KeyError as e:
result = f"Error: Template uses {{{e.args[0]}}} but that input doesn't exist!"
except Exception as e:
result = f"Error: {str(e)}"
print(f"\n[DEBUG F-String]: {result}\n")
return {
"ui": {"text": [result]},
"result": (result,)
}