aboutsummaryrefslogtreecommitdiff
path: root/comfier.py
diff options
context:
space:
mode:
Diffstat (limited to 'comfier.py')
-rw-r--r--comfier.py53
1 files changed, 37 insertions, 16 deletions
diff --git a/comfier.py b/comfier.py
index 33277fb..c32b0d7 100644
--- a/comfier.py
+++ b/comfier.py
@@ -30,18 +30,26 @@ EventCall = Callable[[dict[str, Any]], Awaitable[Any]]
class Tools:
+ """
+ Comfier: ComfyUI image generation for Open WebUI.
+
+ Uses the workflow, connection settings and node mappings (prompt, seed, width,
+ height, steps) configured in Open WebUI's image generation settings, and adds
+ negative prompts, per-call size and reproducible seeds on top.
+ """
+
class Valves(BaseModel):
negative_prompt: str = Field(
default="watermarks",
- description="Tool level value for the negative prompt.",
+ description="Default negative prompt, used when the model does not provide one.",
)
negative_prompt_key: str = Field(
default="negative_prompt",
- description="Tool-level input key name for the negative prompt (e.g. 'negative_prompt' or 'text').",
+ description="Name of the workflow node input that receives the negative prompt (e.g. 'negative_prompt' or 'text').",
)
negative_prompt_node_ids: str = Field(
default="",
- description="Tool-level node IDs for negative prompt targets, comma-separated (e.g. '459:452'). Leave empty to disable negative prompting.",
+ description="Comma-separated IDs of the workflow nodes that receive the negative prompt (e.g. '459:452'). Leave empty to disable negative prompting.",
)
def __init__(self):
@@ -51,11 +59,14 @@ class Tools:
self, bits: Annotated[int, Field(ge=8, le=63)] = 63
) -> str:
"""
- Generate a new seed for image generation.
- This seed can then be used for later calls of comfier_generate_image.
+ Generate a new random seed for image generation.
+
+ Calling this is optional: comfier_generate_image picks a random seed itself and reports it in its result.
+ Use this tool only when a seed is needed before generating, for example to create several images with distinct, known seeds.
+ Returns the seed as a decimal string, which can be passed as the seed of comfier_generate_image.
- :param bits: The maximum bit-width of the generated seed (between 8 and 63).
- :return: The generated seed.
+ :param bits: Maximum bit-width of the seed, between 8 and 63. Larger values allow larger seeds. Defaults to 63.
+ :return: The generated seed as a decimal string.
"""
clamped = max(8, min(int(bits), 63))
@@ -73,14 +84,18 @@ class Tools:
__event_call__: Optional[EventCall] = None,
) -> dict[str, Any]:
"""
- Generate an image from a text prompt using an optional reproducible seed.
- Additionally, this tool allows for the specification of a 'negative prompt'.
-
- :param positive_prompt: The descriptive text prompt for the image to generate.
- :param negative_prompt: Optional descriptive text prompt of what to avoid generating in the image.
- :param size: Optional image dimensions in 'WIDTHxHEIGHT' format (e.g. '1024x768'). Default to the global Open WebUI size.
- :param seed: Optional seed for reproducible generation.
- :return: Generation status.
+ Generate an image from a text prompt with ComfyUI.
+ Optionally accepts a negative prompt (what to avoid), an image size and a seed for reproducible results.
+
+ The generated image is automatically displayed to the user in the chat, so do not embed or link it again; just tell the user it has been created.
+ Generation may take a while. The result contains the seed that was used (random if none was given).
+ To reproduce an image, pass that seed again with the same prompt and size.
+
+ :param positive_prompt: Descriptive text prompt for the image to generate.
+ :param negative_prompt: Optional text describing what to avoid in the image. If omitted, the administrator's default negative prompt is used; pass an empty string for none.
+ :param size: Optional image size in pixels as 'WIDTHxHEIGHT' (e.g. '1024x768'). If omitted, the default size configured in Open WebUI is used.
+ :param seed: Optional non-negative integer seed (or its decimal string) for reproducible generation. If omitted, a random seed is used.
+ :return: A dict with 'status', the 'seed' used, a 'message' for the model and the list of stored image URLs under 'images'.
"""
if __request__ is None:
@@ -190,7 +205,13 @@ class Tools:
mappings: dict[str, dict[str, Any]],
values: dict[str, Any],
) -> dict[str, list[str]]:
- """Inject the resolved parameter values into the workflow dictionary in-place."""
+ """
+ Inject the resolved parameter values into the workflow dictionary in-place.
+
+ Parameters without a mapping or with a value of None are skipped.
+ Returns the injected targets ("node_id.input_key") per parameter name.
+ Raises KeyError if a mapped node does not exist in the workflow.
+ """
applied: dict[str, list[str]] = {}