diff --git a/BasicOllama.png b/BasicOllama.png index 0bb0fb8..f5583ff 100644 Binary files a/BasicOllama.png and b/BasicOllama.png differ diff --git a/BasicOllama.py b/BasicOllama.py index 7875858..fc7a0aa 100644 --- a/BasicOllama.py +++ b/BasicOllama.py @@ -1,117 +1,33 @@ import os import json -import requests import torch import base64 import io -import sys import numpy as np +import aiohttp from PIL import Image -import ctypes -import platform +from comfy_api.latest import ComfyExtension, io as comfy_io, ui as comfy_ui -def print_colored(color, text=""): - if platform.system() != 'Windows': - if color == "success": - print("✔ SUCCESS Oh🦙 API is listening.") - elif color == "failed": - print("⚠ FAILED Could not connect to Oh🦙.") - elif color == "info": - print(f"ℹ INFO: {text}") - return - - # Define necessary structures - class COORD(ctypes.Structure): - _fields_ = [("X", ctypes.c_short), ("Y", ctypes.c_short)] - - class SMALL_RECT(ctypes.Structure): - _fields_ = [("Left", ctypes.c_short), ("Top", ctypes.c_short), - ("Right", ctypes.c_short), ("Bottom", ctypes.c_short)] - - class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure): - _fields_ = [("dwSize", COORD), - ("dwCursorPosition", COORD), - ("wAttributes", ctypes.c_ushort), - ("srWindow", SMALL_RECT), - ("dwMaximumWindowSize", COORD)] - - # Constants for colors - FOREGROUND_WHITE = 0x0007 - FOREGROUND_GREEN = 0x000A - FOREGROUND_RED = 0x000C - FOREGROUND_YELLOW = 0x000E - FOREGROUND_BRIGHT_GREEN = 0x0002 | 0x0008 - BACKGROUND_GREEN = 0x0020 - BACKGROUND_RED = 0x0040 - BACKGROUND_BLUE = 0x0010 - BACKGROUND_PURPLE = BACKGROUND_RED | BACKGROUND_BLUE - - # Get handle to stdout - STD_OUTPUT_HANDLE = -11 - handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) - - # Get original console attributes - csbi = CONSOLE_SCREEN_BUFFER_INFO() - if ctypes.windll.kernel32.GetConsoleScreenBufferInfo(handle, ctypes.byref(csbi)): - reset = csbi.wAttributes - - # Set color - if color == "success": - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, BACKGROUND_GREEN | FOREGROUND_WHITE) - print(" ✔ SUCCESS ", end="") - sys.stdout.flush() - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, FOREGROUND_GREEN | (reset & 0xFFF0)) - print(" Oh🦙 API is listening.") - elif color == "failed": - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, BACKGROUND_RED | FOREGROUND_WHITE) - print(" ⚠ FAILED ", end="") - sys.stdout.flush() - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, FOREGROUND_RED | (reset & 0xFFF0)) - print(" Could not connect to Oh🦙.") - elif color == "info": - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, BACKGROUND_BLUE | FOREGROUND_YELLOW) - sys.stdout.write(f" ℹ INFO: {text} ") - sys.stdout.flush() - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, reset) - sys.stdout.write("\n") - sys.stdout.flush() - return # Prevent double reset - elif color == "image_info": - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, BACKGROUND_PURPLE | FOREGROUND_BRIGHT_GREEN) - sys.stdout.write(f" 🖼 IMAGE: {text} ") - sys.stdout.flush() - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, reset) - sys.stdout.write("\n") - sys.stdout.flush() - return # Prevent double reset - - # Reset to original color - ctypes.windll.kernel32.SetConsoleTextAttribute(handle, reset) - else: - # Fallback to simple print if not in a real console - if color == "success": - print("✔ SUCCESS Oh🦙 API is listening.") - elif color == "failed": - print("⚠ FAILED Could not connect to Oh🦙.") - elif color == "info": - print(f"ℹ INFO: {text}") - elif color == "image_info": - print(f"🖼 IMAGE: {text}") +try: + from server import PromptServer + from aiohttp import web +except ImportError: + PromptServer = None def get_prompt_files(): """Scans the 'prompts' directory for .txt files and returns a dictionary.""" prompt_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'prompts') - if not os.path.exists(prompt_dir): - return {} - prompt_files = {} - for filename in os.listdir(prompt_dir): - if filename.endswith(".txt"): - filepath = os.path.join(prompt_dir, filename) - with open(filepath, 'r', encoding='utf-8') as f: - # Use filename without extension as the key - key = os.path.splitext(filename)[0] - prompt_files[key] = f.read().strip() + if os.path.exists(prompt_dir): + for filename in os.listdir(prompt_dir): + if filename.endswith(".txt"): + filepath = os.path.join(prompt_dir, filename) + try: + with open(filepath, 'r', encoding='utf-8') as f: + key = os.path.splitext(filename)[0] + prompt_files[key] = f.read().strip() + except Exception as e: + print(f"BasicOllama: Error reading prompt file {filename}: {e}") return prompt_files def rgba_to_rgb(image): @@ -121,181 +37,228 @@ def rgba_to_rgb(image): image = Image.alpha_composite(background.convert("RGBA"), image).convert("RGB") return image -def tensor_to_pil_image(tensor): - """Convert tensor to PIL Image with RGBA support""" - tensor = tensor.cpu() - image_np = tensor.squeeze().mul(255).clamp(0, 255).byte().numpy() - - # Handle different channel counts - if len(image_np.shape) == 2: # Grayscale - image_np = np.expand_dims(image_np, axis=-1) - if image_np.shape[-1] == 1: # Single channel +def tensor_to_pil(tensor): + """Convert a [H, W, C] tensor to PIL Image""" + if tensor.dim() == 4: + tensor = tensor[0] + + image_np = tensor.cpu().numpy() + image_np = (image_np * 255).clip(0, 255).astype(np.uint8) + + if image_np.shape[-1] == 1: image_np = np.repeat(image_np, 3, axis=-1) - - channels = image_np.shape[-1] - mode = 'RGBA' if channels == 4 else 'RGB' - + + mode = 'RGBA' if image_np.shape[-1] == 4 else 'RGB' image = Image.fromarray(image_np, mode=mode) return rgba_to_rgb(image) def tensor_to_base64(tensor): """Convert tensor to base64 encoded PNG""" - image = tensor_to_pil_image(tensor) + image = tensor_to_pil(tensor) buffered = io.BytesIO() image.save(buffered, format="PNG") return base64.b64encode(buffered.getvalue()).decode() def get_ollama_url(): - try: - config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config.json') - with open(config_path, 'r') as f: - config = json.load(f) - ollama_url = config.get("OLLAMA_URL", "http://localhost:11434") - except FileNotFoundError: - print("Error: config.json not found, using default Ollama URL.") - ollama_url = "http://localhost:11434" - except json.JSONDecodeError: - print("Error: Could not decode config.json, using default Ollama URL.") - ollama_url = "http://localhost:11434" - except Exception as e: - print(f"An unexpected error occurred: {e}, using default Ollama URL.") - ollama_url = "http://localhost:11434" + config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config.json') + ollama_url = "http://localhost:11434" + if os.path.exists(config_path): + try: + with open(config_path, 'r') as f: + config = json.load(f) + ollama_url = config.get("OLLAMA_URL", ollama_url) + except Exception as e: + print(f"BasicOllama: Error reading config.json: {e}") return ollama_url -class BasicOllama: - _connection_error_printed = False - _success_message_printed = False - - def __init__(self): - self.ollama_url = get_ollama_url() +async def fetch_ollama_models(): + url = f"{get_ollama_url()}/api/tags" + try: + async with aiohttp.ClientSession() as session: + async with session.get(url, timeout=2) as response: + if response.status == 200: + data = await response.json() + models = data.get('models', []) + return [model['name'] for model in models] + except Exception: + pass + return ["Start Ollama and Refresh"] +class BasicOllama(comfy_io.ComfyNode): @classmethod - def get_ollama_models(cls): - ollama_url = get_ollama_url() - try: - response = requests.get(f"{ollama_url}/api/tags") - response.raise_for_status() - models = response.json().get('models', []) - - if not cls._success_message_printed: - print_colored("success") - cls._success_message_printed = True - - cls._connection_error_printed = False # Reset on success - return [model['name'] for model in models] - except requests.exceptions.RequestException: - cls._success_message_printed = False # Reset on failure - if not cls._connection_error_printed: - print_colored("failed") - cls._connection_error_printed = True - return [] - - @classmethod - def INPUT_TYPES(cls): - # Dynamically get the list of prompt structures from the filenames - prompt_structures = list(get_prompt_files().keys()) + def define_schema(cls) -> comfy_io.Schema: + prompt_templates = get_prompt_files() + prompt_structures = list(prompt_templates.keys()) if not prompt_structures: - prompt_structures = ["None"] # Fallback if no files are found + prompt_structures = ["None"] - return { - "required": { - "prompt": ("STRING", {"default": "", "multiline": True}), - "ollama_model": (cls.get_ollama_models(),), - "keep_alive": ("INT", {"default": 0, "min": 0, "max": 60, "step": 1}), - "saved_sys_prompt": (prompt_structures,), - "use_sys_prompt_below": ("BOOLEAN", {"default": False}), - "system_prompt": ("STRING", {"default": "", "multiline": True}), - }, - "optional": { - } - } + return comfy_io.Schema( + node_id="BasicOllama", + display_name="Basic Ollama", + category="Ollama", + description="Interface with Ollama LLMs, supporting dynamic image inputs.", + is_output_node=False, + inputs=[ + comfy_io.String.Input("prompt", multiline=True, tooltip="The main text prompt for the LLM."), + comfy_io.MultiType.Input( + comfy_io.Combo.Input("ollama_model", + options=["Loading..."], + default="Loading...", + tooltip="Select the Ollama model to use.", + socketless=True, + remote=comfy_io.RemoteOptions( + route="/basic_ollama/models", + refresh_button=True + )), + types=[comfy_io.String] + ), + comfy_io.Int.Input( + "generation_seed", + default=0, + min=0, + max=0xffffffffffffffff, + step=1, + control_after_generate=True, + tooltip="Seed for randomness. Change this to force a new generation." + ), + comfy_io.Boolean.Input("enable_think", default=True, tooltip="Enable reasoning/thinking for supported models."), + comfy_io.Combo.Input( + "saved_sys_prompt", + options=prompt_structures, + default=prompt_structures[0], + tooltip="Select a pre-defined system prompt." + ), + comfy_io.Boolean.Input("use_sys_prompt_below", default=False, tooltip="If True, use the custom system prompt below instead of the saved one."), + comfy_io.String.Input("system_prompt", multiline=True, tooltip="Custom system prompt to guide the LLM's behavior."), + comfy_io.Autogrow.Input("images", + comfy_io.Autogrow.TemplatePrefix(comfy_io.Image.Input("image", optional=True), prefix="image", min=1, max=10), + optional=True, + extra_dict={"autoshrink": True}, + tooltip="Dynamic image inputs for multimodal models.") + ], + outputs=[ + comfy_io.String.Output(id="text", display_name="text", tooltip="The text generated by the LLM."), + comfy_io.String.Output(id="thinking", display_name="thinking", tooltip="The reasoning trace (if available).") + ], + hidden=[comfy_io.Hidden.unique_id] + ) - RETURN_TYPES = ("STRING",) - RETURN_NAMES = ("text",) - FUNCTION = "generate_content" - CATEGORY = "Ollama" + @classmethod + def validate_inputs(cls, **kwargs) -> bool | str: + return True - def generate_content(self, prompt, ollama_model, keep_alive, use_sys_prompt_below, saved_sys_prompt, system_prompt, **kwargs): - url = f"{self.ollama_url}/api/generate" + @classmethod + async def execute(cls, prompt, ollama_model, generation_seed, enable_think, use_sys_prompt_below, saved_sys_prompt, system_prompt, images=None, **kwargs) -> comfy_io.NodeOutput: + ollama_url = get_ollama_url() + url = f"{ollama_url}/api/generate" system_prompt_content = "" if use_sys_prompt_below: system_prompt_content = system_prompt - print_colored("info", "Applying User provided system prompt") else: prompt_templates = get_prompt_files() if saved_sys_prompt in prompt_templates: system_prompt_content = prompt_templates[saved_sys_prompt] - print_colored("info", f"Applying {saved_sys_prompt} system prompt") payload = { "model": ollama_model, "prompt": prompt, "stream": False, - "keep_alive": f"{keep_alive}m", + "keep_alive": "0m", + "options": { + "seed": generation_seed + } } + # Handle 'think' parameter logic + payload["think"] = enable_think + if system_prompt_content: payload["system"] = system_prompt_content - all_images = [kwargs[key] for key in sorted(kwargs.keys()) if key.startswith('image')] - provided_images = [img for img in all_images if img is not None] + # Collect all images from the 'images' dict (Autogrow) and any stray images in kwargs + provided_images = [] + + # Check the packed 'images' dictionary + if isinstance(images, dict): + for key in sorted(images.keys()): + img_tensor = images[key] + if isinstance(img_tensor, torch.Tensor): + for i in range(img_tensor.shape[0]): + provided_images.append(img_tensor[i]) + + # Check kwargs for any stray image inputs + for k, v in kwargs.items(): + if k.startswith("image") and isinstance(v, torch.Tensor): + # Avoid duplicates if already in 'images' dict + if not isinstance(images, dict) or k not in images: + for i in range(v.shape[0]): + provided_images.append(v[i]) if provided_images: - print_colored("image_info", f"Processing {len(provided_images)} image(s) for Ollama API") image_data = [tensor_to_base64(img) for img in provided_images] payload["images"] = image_data try: - response = requests.post(url, json=payload) - response.raise_for_status() + # Set a timeout (10 minutes) for model inference + timeout = aiohttp.ClientTimeout(total=600) + async with aiohttp.ClientSession(timeout=timeout) as session: + async with session.post(url, json=payload) as response: + if response.status != 200: + error_text = await response.text() + # Return empty strings on error to match output signature + return comfy_io.NodeOutput(f"Error: {response.status} - {error_text}", "") + + data = await response.json() + text_output = data.get('response', '') + thinking_output = data.get('thinking', '') - textoutput = response.json().get('response', '') + if text_output.strip(): + text_output = cls.clean_text(text_output) - if textoutput.strip(): - clean_text = textoutput.strip() - # Remove triple backticks (```) that might wrap the output, often seen in code blocks from LLMs - if clean_text.startswith("```") and "```" in clean_text[3:]: - first_block_end = clean_text.find("```", 3) - if first_block_end > 3: - # Attempt to remove language identifier if present (e.g., ```json) - language_line_end = clean_text.find("\n", 3) - if language_line_end > 3 and language_line_end < first_block_end: - clean_text = clean_text[language_line_end+1:first_block_end].strip() - else: - clean_text = clean_text[3:first_block_end].strip() + return comfy_io.NodeOutput(text_output, thinking_output) - # Remove surrounding quotes if the entire output is quoted (e.g., "generated text") - if (clean_text.startswith('"') and clean_text.endswith('"')) or (clean_text.startswith("'") and clean_text.endswith("'")): - clean_text = clean_text[1:-1].strip() - - # Remove common prefixes that LLMs might add (e.g., "Prompt:", "Final Prompt:") - prefixes_to_remove = ["Prompt:", "PROMPT:", "Generated Prompt:", "Final Prompt:"] - for prefix in prefixes_to_remove: - if clean_text.startswith(prefix): - clean_text = clean_text[len(prefix):].strip() - break - - textoutput = clean_text - - return (textoutput,) - except requests.exceptions.RequestException as e: - error_message = f"API Error: {e}" - if e.response: - error_message += f"\nStatus Code: {e.response.status_code}" - try: - error_message += f"\nResponse: {e.response.json()}" - except json.JSONDecodeError: - error_message += f"\nResponse: {e.response.text}" - return (error_message,) except Exception as e: - return (f"An unexpected error occurred: {e}",) + return comfy_io.NodeOutput(f"Connection Error: {e}. Ensure Ollama is running at {ollama_url}") -NODE_CLASS_MAPPINGS = { - "BasicOllama": BasicOllama, -} + @staticmethod + def clean_text(text): + clean_text = text.strip() + if clean_text.startswith("```") and "```" in clean_text[3:]: + first_block_end = clean_text.find("```", 3) + if first_block_end > 3: + language_line_end = clean_text.find("\n", 3) + if language_line_end > 3 and language_line_end < first_block_end: + clean_text = clean_text[language_line_end+1:first_block_end].strip() + else: + clean_text = clean_text[3:first_block_end].strip() -NODE_DISPLAY_NAME_MAPPINGS = { - "BasicOllama": "Basic Ollama", -} + if (clean_text.startswith('"') and clean_text.endswith('"')) or (clean_text.startswith("'") and clean_text.endswith("'")): + clean_text = clean_text[1:-1].strip() + prefixes_to_remove = ["Prompt:", "PROMPT:", "Generated Prompt:", "Final Prompt:"] + for prefix in prefixes_to_remove: + if clean_text.startswith(prefix): + clean_text = clean_text[len(prefix):].strip() + break + + return clean_text + +async def get_ollama_models_endpoint(request): + models = await fetch_ollama_models() + return web.json_response(models) + +if PromptServer: + try: + @PromptServer.instance.routes.get("/basic_ollama/models") + async def get_ollama_models_endpoint_handler(request): + return await get_ollama_models_endpoint(request) + except Exception as e: + print(f"BasicOllama: Could not register API route: {e}") + +class BasicOllamaExtension(ComfyExtension): + async def get_node_list(self) -> list[type[comfy_io.ComfyNode]]: + return [BasicOllama] + +async def comfy_entrypoint() -> BasicOllamaExtension: + return BasicOllamaExtension() diff --git a/README.md b/README.md index 7b12d4d..b8eb12e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ComfyUI-BasicOllama -A simplified node that provides access to Ollama. It allows you to send prompts, system prompts, and images to your Ollama instance and receive text-based responses. +A simplified node that provides access to Ollama. It allows you to send prompts and images to your Ollama instance and receive text-based responses with support for reasoning/thinking and system prompts. ## ⚠️ Requirements @@ -8,15 +8,15 @@ A simplified node that provides access to Ollama. It allows you to send prompts, ## 🚀 Features +* **Zero Startup Impact:** This node loads asynchronously and will not slow down your ComfyUI browser loading time. * **Direct Ollama Integration:** Seamlessly connect to your local Ollama instance. * **Automatic Image Detection:** The node automatically detects if an image is connected and sends it to Ollama for multimodal analysis. +* **Reasoning Support:** Toggle "think" mode to capture reasoning traces. * **System Prompt Support:** Utilize the `system` parameter in the Ollama API for more control over model behavior. * **Dynamic Prompt Templates:** Easily load your own system prompts from `.txt` files in the `prompts` directory. * **Dynamic Image Inputs:** Start with one image input, and automatically add more as you connect them. * **Easy Configuration:** Quickly set up your Ollama URL via a `config.json` file. -![](https://github.com/BobRandomNumber/ComfyUI-BasicOllama/blob/main/BasicOllama.png) - ## 📦 Installation 1. **Clone the Repository:** @@ -26,17 +26,7 @@ A simplified node that provides access to Ollama. It allows you to send prompts, git clone https://github.com/BobRandomNumber/ComfyUI-BasicOllama.git ``` -2. **Install Dependencies:** - Navigate to the newly cloned directory and install the required packages: -  -```bash - cd ComfyUI-BasicOllama -``` -```bash - pip install -r requirements.txt -``` - -3. **Restart your ComfyUI instance to load the new custom node.** +2. **Restart your ComfyUI instance to load the new custom node.** ## ✨ Usage @@ -47,18 +37,20 @@ The `BasicOllama` node can be found under the `Ollama` category in the ComfyUI m | Name | Type | Description | | ---------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `prompt` | `STRING` | The main text prompt to send to the Ollama model. | -| `ollama_model` | `COMBO` | A list of available Ollama models on your local instance. | -| `keep_alive` | `INT` | The duration (in minutes) that the Ollama model should remain loaded in memory after the request is complete. | -| `saved_sys_prompt` | `COMBO` | A dropdown list of saved system prompts from the `.txt` files in the `prompts` directory. This is used as the system prompt by default. | -| `use_sys_prompt_below` | `BOOLEAN` | If checked (`True`), the `system_prompt` text box below will be used instead of the dropdown selection. If unchecked (`False`), the `saved_sys_prompt` dropdown is used. | -| `system_prompt` | `STRING` | A multiline text box for a custom, one-off system prompt. This is only active when `use_sys_prompt_below` is checked. | -| `image` | `IMAGE` | An optional image input for multimodal models. The node starts with one image input, and connecting an image to it will create a new input, allowing for any number of images. | +| `ollama_model` | `COMBO` | Asynchronously populated list of available Ollama models. Use the **Refresh** button to update the list from your Ollama instance. | +| `generation_seed` | `INT` | Seed for randomness. Includes control for incrementing or fixing the seed after generation. | +| `enable_think` | `BOOLEAN` | If enabled, requests and captures the reasoning/thinking trace for supported models. | +| `saved_sys_prompt` | `COMBO` | A dropdown list of saved system prompts from the `.txt` files in the `prompts` directory. | +| `use_sys_prompt_below` | `BOOLEAN` | If checked (`True`), the `system_prompt` text box below will be used instead of the dropdown selection. | +| `system_prompt` | `STRING` | A multiline text box for a custom, one-off system prompt. | +| `image` | `IMAGE` | Optional image inputs for multimodal models. Connecting an image automatically creates a new input slot. | ### Outputs -| Name | Type | Description | -| ------ | -------- | ----------------------------------------- | -| `text` | `STRING` | The text-based response from the Ollama model. | +| Name | Type | Description | +| ---------- | -------- | --------------------------------------------------------------------------- | +| `text` | `STRING` | The main text-based response from the Ollama model. | +| `thinking` | `STRING` | The reasoning trace generated by the model (if `enable_think` is active). | ## ✍️ Adding Custom System Prompts @@ -66,16 +58,10 @@ You can easily add your own reusable system prompts to the `saved_sys_prompt` dr 1. Navigate to the `ComfyUI-BasicOllama/prompts` directory. 2. Create a new text file (e.g., `my_prompt.txt`). -3. Write your system prompt inside this file. For example, if you want a system prompt for generating JSON, the content of the file could be: +3. Write your system prompt inside this file. +4. Save the file and refresh your ComfyUI browser window. -  ``` - You are a helpful assistant that only responds with valid, well-formatted JSON. - ``` - -4. Save the file. -5. Refresh your ComfyUI browser window. - -The name of your file (without the `.txt` extension) will now appear as an option in the `saved_sys_prompt` dropdown. In the example above, you would see `my_prompt` in the list. +The name of your file (without the `.txt` extension) will now appear as an option in the `saved_sys_prompt` dropdown. ## ⚙️ Configuration @@ -91,6 +77,6 @@ If your Ollama instance is running on a different URL/port, you can change it by ## 🙏 Attribution -A special thank you to [@al-swaiti](https://github.com/al-swaiti) for creating the original [ComfyUI-OllamaGemini](https://github.com/al-swaiti/ComfyUI-OllamaGemini) whose Ollama node served as the foundation and inspiration for this. +A special thank you to [@al-swaiti](https://github.com/al-swaiti) for creating the original [ComfyUI-OllamaGemini](https://github.com/al-swaiti/ComllamaGemini) whose Ollama node served as the foundation and inspiration for this. This project is licensed under the [MIT License](LICENSE). diff --git a/__init__.py b/__init__.py index 3214059..c58573c 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,5 @@ -from .BasicOllama import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS +from .BasicOllama import comfy_entrypoint -WEB_DIRECTORY = "./web" -__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', 'WEB_DIRECTORY'] +WEB_DIRECTORY = "./js" + +__all__ = ['comfy_entrypoint', 'WEB_DIRECTORY'] \ No newline at end of file diff --git a/js/basic_ollama_ui.js b/js/basic_ollama_ui.js new file mode 100644 index 0000000..91df0ef --- /dev/null +++ b/js/basic_ollama_ui.js @@ -0,0 +1,41 @@ +import { app } from "../../scripts/app.js"; + +app.registerExtension({ + name: "BasicOllama.HideAutoRefresh", + async beforeRegisterNodeDef(nodeType, nodeData, app) { + // Only target your specific node + if (nodeData.name === "BasicOllama") { + const onNodeCreated = nodeType.prototype.onNodeCreated; + + nodeType.prototype.onNodeCreated = function () { + if (onNodeCreated) { + onNodeCreated.apply(this, arguments); + } + + // Intercept ANY widget ComfyUI tries to add to this node + const origAddWidget = this.addWidget; + this.addWidget = function (type, name, value, callback, options) { + // Let the widget be created so ComfyUI's backend doesn't crash + const w = origAddWidget.apply(this, arguments); + + // If the widget is the annoying auto-refresh toggle, hide it instantly + if (name && typeof name === "string" && name.toLowerCase().includes("auto-refresh")) { + w.type = "hidden"; // Tell LiteGraph not to draw it + w.computeSize = () => [0, -4]; // Force its height to 0 pixels + } + return w; + }; + + // Cleanup: just in case it was already added before interception + if (this.widgets) { + for (let w of this.widgets) { + if (w.name && w.name.toLowerCase().includes("auto-refresh")) { + w.type = "hidden"; + w.computeSize = () => [0, -4]; + } + } + } + }; + } + } +}); \ No newline at end of file diff --git a/prompts/LTX2_I2V.txt b/prompts/LTX2_I2V.txt new file mode 100644 index 0000000..2eb743f --- /dev/null +++ b/prompts/LTX2_I2V.txt @@ -0,0 +1,31 @@ +You are a Creative Assistant. Given a user's raw input prompt describing a scene or concept, expand it into a detailed video generation prompt with specific visuals and integrated audio to guide a text-to-video model. +You are a Creative Assistant writing concise, action-focused image-to-video prompts. Given an image (first frame) and user Raw Input Prompt, generate a prompt to guide video generation from that image. + +#### Guidelines: +- Analyze the Image: Identify Subject, Setting, Elements, Style and Mood. +- Follow user Raw Input Prompt: Include all requested motion, actions, camera movements, audio, and details. If in conflict with the image, prioritize user request while maintaining visual consistency (describe transition from image to user's scene). +- Describe only changes from the image: Don't reiterate established visual details. Inaccurate descriptions may cause scene cuts. +- Active language: Use present-progressive verbs ("is walking," "speaking"). If no action specified, describe natural movements. +- Chronological flow: Use temporal connectors ("as," "then," "while"). +- Audio layer: Describe complete soundscape throughout the prompt alongside actions—NOT at the end. Align audio intensity with action tempo. Include natural background audio, ambient sounds, effects, speech or music (when requested). Be specific (e.g., "soft footsteps on tile") not vague (e.g., "ambient sound"). +- Speech (only when requested): Provide exact words in quotes with character's visual/voice characteristics (e.g., "The tall man speaks in a low, gravelly voice"), language if not English and accent if relevant. If general conversation mentioned without text, generate contextual quoted dialogue. (i.e., "The man is talking" input -> the output should include exact spoken words, like: "The man is talking in an excited voice saying: 'You won't believe what I just saw!' His hands gesture expressively as he speaks, eyebrows raised with enthusiasm. The ambient sound of a quiet room underscores his animated speech.") +- Style: Include visual style at beginning: "Style: