diff --git a/README.md b/README.md index f3cbc1b..c2adde9 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Name | Description :--- | :--- Loader | Used to load EXL2/GPTQ Llama models. You can find a lot of them on [Hugging Face](https://huggingface.co/TheBloke). Clone the model repository or download all the files in it and place them in an empty directory, then specify the path in `model_dir`. The `model.safetensors` file won't work on its own.

ExLlama allocates memory based on `max_seq_len`. Lowering it is a good way to save on VRAM. It's currently not possible to offload the model to RAM. Generator | Generates a `string` based on the given input for use with other nodes. Default values correspond to the `simple-1` preset from [text-generation-webui](https://github.com/oobabooga/text-generation-webui).

ExLlama isn't deterministic, so the outputs may differ even with the same seed. -Formatter | Replaces variables enclosed in brackets, such as `[a]`, with their values. Previewer | Displays generated outputs in the UI and appends them to workflow metadata. +Replacer | Replaces variables enclosed in brackets, such as `[a]`, with their values. ## Workflow The image below can be opened in ComfyUI. The [model](https://huggingface.co/turboderp/Mistral-7B-instruct-exl2/tree/2.5bpw) uses around 3-4GB of VRAM depending on sequence length. diff --git a/__init__.py b/__init__.py index 81974c0..8def457 100644 --- a/__init__.py +++ b/__init__.py @@ -1,17 +1,17 @@ -from .nodes import Formatter, Generator, Loader, Previewer +from .nodes import Generator, Loader, Previewer, Replacer NODE_CLASS_MAPPINGS = { "ZuellniExLlamaLoader": Loader, "ZuellniExLlamaGenerator": Generator, - "ZuellniTextFormatter": Formatter, "ZuellniTextPreviewer": Previewer, + "ZuellniTextReplacer": Replacer, } NODE_DISPLAY_NAME_MAPPINGS = { "ZuellniExLlamaLoader": "ExLlama Loader", "ZuellniExLlamaGenerator": "ExLlama Generator", - "ZuellniTextFormatter": "Format Text", "ZuellniTextPreviewer": "Preview Text", + "ZuellniTextReplacer": "Replace Text", } WEB_DIRECTORY = "." diff --git a/nodes.py b/nodes.py index 4170131..8d530a5 100644 --- a/nodes.py +++ b/nodes.py @@ -101,32 +101,6 @@ class Generator: return (text.strip(),) -class Formatter: - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "text": ("STRING", {"default": "", "multiline": True}), - }, - "optional": { - "a": ("STRING", {"forceInput": True, "multiline": True}), - "b": ("STRING", {"forceInput": True, "multiline": True}), - "c": ("STRING", {"forceInput": True, "multiline": True}), - }, - } - - CATEGORY = "Zuellni/Text" - FUNCTION = "format" - RETURN_NAMES = ("TEXT",) - RETURN_TYPES = ("STRING",) - - def format(self, text, **vars): - for key, value in vars.items(): - text = text.replace(f"[{key}]", value) - - return (text,) - - class Previewer: @classmethod def INPUT_TYPES(cls): @@ -147,10 +121,37 @@ class Previewer: def preview(self, text, info=None, id=None): if id and info and "workflow" in info: - workflow = info["workflow"] - node = next((n for n in workflow["nodes"] if str(n["id"]) == id), None) + nodes = info["workflow"]["nodes"] + node = next((n for n in nodes if str(n["id"]) == id), None) if node: node["widgets_values"] = [text] return {"ui": {"text": [text]}} + + +class Replacer: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text": ("STRING", {"default": "", "multiline": True}), + }, + "optional": { + "a": ("STRING", {"forceInput": True, "multiline": True}), + "b": ("STRING", {"forceInput": True, "multiline": True}), + "c": ("STRING", {"forceInput": True, "multiline": True}), + "d": ("STRING", {"forceInput": True, "multiline": True}), + } + } + + CATEGORY = "Zuellni/Text" + FUNCTION = "replace" + RETURN_NAMES = ("TEXT",) + RETURN_TYPES = ("STRING",) + + def replace(self, text, **vars): + for key, value, in vars.items(): + text = text.replace(f"[{key}]", value) + + return (text,)