From 4901286feceb55dee7de0c293f07a7746b2db707 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Sat, 14 Feb 2026 19:21:14 -0500 Subject: [PATCH] Not working, but the roundtrip-scaffolding is there. --- __init__.py | 6 ++++ nodes/ollama_generate_string.py | 40 +++++++++++++++++++++++++ web/ollama_generate_string.js | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 nodes/ollama_generate_string.py create mode 100644 web/ollama_generate_string.js diff --git a/__init__.py b/__init__.py index c624476..31d0306 100644 --- a/__init__.py +++ b/__init__.py @@ -4,6 +4,7 @@ from .nodes.string_replace import StringReplace from .nodes.string_node import StringNode from .nodes.string_concat import StringConcat from .nodes.string_from_int import StringFromInt +from .nodes.ollama_generate_string import OllamaGenerateString from .nodes.tokenizer_vocab import TokenizerVocab @@ -24,6 +25,7 @@ NODE_CLASS_MAPPINGS = { "IW_JsonPickItem": JsonPickItem, "IW_ModelHook": ModelHook, + "IW_OllamaGenerateString": OllamaGenerateString, } # A dictionary that contains the friendly/humanly readable titles for the nodes @@ -40,5 +42,9 @@ NODE_DISPLAY_NAME_MAPPINGS = { "IW_JsonPickItem": "IW JsonPickItem", "IW_ModelHook": "IW ModelHook", + "IW_OllamaGenerateString": "IW Ollama Generate String", } + + +WEB_DIRECTORY = "./web" \ No newline at end of file diff --git a/nodes/ollama_generate_string.py b/nodes/ollama_generate_string.py new file mode 100644 index 0000000..ed44b62 --- /dev/null +++ b/nodes/ollama_generate_string.py @@ -0,0 +1,40 @@ +import os +import json +from collections import deque + +from server import PromptServer +class OllamaGenerateString : + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "int_value": ("INT",{"defaultInput": True}), + "prompt": ("STRING",{"defaultInput": True, "default": "", "multiline": True, "dynamicPrompts": False}), + }, + "optional": { + }, + } + + RETURN_TYPES = ("STRING", ) + FUNCTION = "execute" + OUTPUT_IS_LIST = (True,) + + CATEGORY = "iw" + + @classmethod + def IS_CHANGED(cls, int_value, prompt ): + return "foo" + + + def execute(self, int_value, prompt): + result = (prompt,) + print("Executing with ", prompt) + print(" generating new with ", int_value) + return { "ui": { "next_int": [int_value], "next_value": [f"super cool: {int_value}"]}, "result": [result] } + +@PromptServer.instance.routes.get("/iw/api/ollama_generate") +async def load_drawing(request): + print("/iw/api/ollama_generate") diff --git a/web/ollama_generate_string.js b/web/ollama_generate_string.js new file mode 100644 index 0000000..171de58 --- /dev/null +++ b/web/ollama_generate_string.js @@ -0,0 +1,52 @@ +import { app } from "../../scripts/app.js"; +import { api } from "../../scripts/api.js"; +import { ComfyWidgets } from "../../scripts/widgets.js"; + +app.registerExtension({ + name: "iw.ollama.generate", + + async beforeRegisterNodeDef(nodeType, nodeData, app) { + let find_widget = (node, name) => node.widgets.find((w) => w.name === name); + if (nodeData.name === "IW_OllamaGenerateString") { + console.log("Something ollama thing"); + nodeType.prototype.initState = function () { + console.log("hello"); + }; + nodeType.prototype.initWidgets = function (app) { + this.setupWidgets(); + }; + + nodeType.prototype.setupWidgets = function (app) { + this.addWidget( + "combo", + "model", + "unknown", + (value) => { + this.tool = value; + }, + { + values: ["a", "b", "c"], + default: "unknown", + } + ); + + }; + + + nodeType.prototype.onNodeCreated = function () { + this.initWidgets(app); + this.initState(); + }; + + nodeType.prototype.onExecuted = function (ui) { + // This is after the fact... so we ready the next value. + console.log("onExecuted next_value", ui.next_value); + let w = find_widget(this, "prompt"); + w.value = ui.next_value; + w.setValue(w.value, false, true); + + } + } + } +}); + \ No newline at end of file