Skip to content

Commit 050c673

Browse files
authored
feat(api-nodes): add copy button to Gemini Chat node (Comfy-Org#9440)
1 parent 497d41f commit 050c673

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

comfy_api_nodes/nodes_gemini.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
from __future__ import annotations
66

77

8+
import json
9+
import time
810
import os
11+
import uuid
912
from enum import Enum
1013
from typing import Optional, Literal
1114

@@ -350,7 +353,27 @@ async def api_call(
350353
# Get result output
351354
output_text = self.get_text_from_response(response)
352355
if unique_id and output_text:
353-
PromptServer.instance.send_progress_text(output_text, node_id=unique_id)
356+
# Not a true chat history like the OpenAI Chat node. It is emulated so the frontend can show a copy button.
357+
render_spec = {
358+
"node_id": unique_id,
359+
"component": "ChatHistoryWidget",
360+
"props": {
361+
"history": json.dumps(
362+
[
363+
{
364+
"prompt": prompt,
365+
"response": output_text,
366+
"response_id": str(uuid.uuid4()),
367+
"timestamp": time.time(),
368+
}
369+
]
370+
),
371+
},
372+
}
373+
PromptServer.instance.send_sync(
374+
"display_component",
375+
render_spec,
376+
)
354377

355378
return (output_text or "Empty response from Gemini model...",)
356379

0 commit comments

Comments
 (0)