comfyanonymous / ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.
https://www.comfy.org/
GNU General Public License v3.0
54.59k stars 5.76k forks source link

How to save text using custom nodes through websocket #5362

Closed mm-diff closed 1 hour ago

mm-diff commented 2 hours ago

Your question

I implemented the following nodes in the same way as SaveImageWebsocket, but the resulting json format is wrong.

import comfy.utils from server import PromptServer, BinaryEventTypes

class SaveTextWebsocket: @classmethod def INPUT_TYPES(s): return {"required": {"text": ("STRING", ),} }

RETURN_TYPES = ()
FUNCTION = "save_text"

OUTPUT_NODE = True

CATEGORY = "api/text"

def save_text(self, text):
    server = PromptServer.instance
    server.send_json(0, text, server.client_id)

    return {"ui": {"text": text}}

Logs

{'type': 'executed', 'data': {'node': 'save_text_websocket_node', 'display_node': 'save_text_websocket_node', 'output': {'text': ['t', 'h', 'e', 'r', 'e', ' ', 'i', 's', ' ', 'a', ' ', 'p', 'l', 'a', 'n', 't', ' ', 'i', 'n', ' ', 'a', ' ', 'p', 'o', 't', ' ', 'w', 'i', 't', 'h', ' ', 'a', ' ', 'f', 'i', 's', 'h', ' ', 'd', 'e', 's', 'i', 'g', 'n', ' ', 'o', 'n', ' ', 'i', 't', ',', ' ', 'f', 'e', 'a', 't', 'u', 'r', 'e', 'd', ' ', 'o', 'n', ' ', 'a', 'm', 'i', 'a', 'm', 'i', ',', ' ', 'c', 'u', 't', 'e', ' ', 's', 'i', 'n', 'g', 'l', 'e', ' ', 'a', 'n', 'i', 'm', 'a', 'l', ',', ' ', 'b', 'e', 'i', 'g', 'e', ' ', 'b', 'a', 'c', 'k', 'g', 'r', 'o', 'u', 'n', 'd', ',', ' ', 'i', 'v', 'y', ',', ' ', 'i', 'n', 's', 'p', 'i', 'r', 'e', 'd', ' ', 'b', 'y', ' ', 'J', 'e', 'm', 'i', 'm', 'a', ' ', 'B', 'l', 'a', 'c', 'k', 'b', 'u', 'r', 'n', ',', ' ', 'm', 'e', 'o', 'w', ',', ' ', 'h', 'i', 'g', 'h', '-', 'q', 'u', 'a', 'l', 'i', 't', 'y', ' ', 'r', 'e', 'n', 'd', 'e', 'r', ',', ' ', 'w', 'i', 't', 'h', ' ', 'a', ' ', 'w', 'h', 'i', 't', 'e', ' ', 'm', 'u', 'g', ',', ' ', 'a', 'q', 'u', 'a', 'r', 'i', 'u', 'm', ' ', 'l', 'i', 'f', 'e', ',', ' ', 'l', 'i', 'l', 'l', 'i', 'e', 's', ',', ' ', 'd', 'i', 'c', 'h', 'r', 'o', 'm', 'a', 't', 'i', 's', 'm', ',', ' ', 'a', 'p', 'p', ',', ' ', 'g', 'r', 'e', 'e', 'n', ':', ' ', '0', '.', '5', ',', ' ', 'c', 'o', 'o', 'k', 'y', ',', ' ', 'h', 'e', 'i', 'g', 'h', 't', ' ', '1', ' ', '7', ' ', '8']}, 'prompt_id': 'xxx'}}

Other

No response

mm-diff commented 1 hour ago

I just wanna get the text content of the custom node via API

mm-diff commented 1 hour ago

the following way works

def save_text(self, text): server = PromptServer.instance server.send_sync("xx", text, server.client_id)

    return {}