Skip to content

Commit 235d390

Browse files
Add method to stream text to node UI (#8018)
* show text progress preview * include node id in message
1 parent d426136 commit 235d390

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

server.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
from app.user_manager import UserManager
3333
from app.model_manager import ModelFileManager
3434
from app.custom_node_manager import CustomNodeManager
35-
from typing import Optional
35+
from typing import Optional, Union
3636
from api_server.routes.internal.internal_routes import InternalRoutes
3737

3838
class BinaryEventTypes:
3939
PREVIEW_IMAGE = 1
4040
UNENCODED_PREVIEW_IMAGE = 2
41+
TEXT = 3
4142

4243
async def send_socket_catch_exception(function, message):
4344
try:
@@ -878,3 +879,15 @@ def trigger_on_prompt(self, json_data):
878879
logging.warning(traceback.format_exc())
879880

880881
return json_data
882+
883+
def send_progress_text(
884+
self, text: Union[bytes, bytearray, str], node_id: str, sid=None
885+
):
886+
if isinstance(text, str):
887+
text = text.encode("utf-8")
888+
node_id_bytes = str(node_id).encode("utf-8")
889+
890+
# Pack the node_id length as a 4-byte unsigned integer, followed by the node_id bytes
891+
message = struct.pack(">I", len(node_id_bytes)) + node_id_bytes + text
892+
893+
self.send_sync(BinaryEventTypes.TEXT, message, sid)

0 commit comments

Comments
 (0)