Fixing invoke_prompt

This commit is contained in:
Cyber MacGeddon 2025-12-04 20:00:11 +00:00
parent 31494d14e1
commit 75eb02e546

View file

@ -31,36 +31,16 @@ def query(url, flow_id, template_id, variables, streaming=True, token=None):
) )
if streaming: if streaming:
full_response = {"text": "", "object": ""} # Stream output (prompt yields strings directly)
# Stream output
for chunk in response: for chunk in response:
content = chunk.content if chunk:
if content: print(chunk, end="", flush=True)
print(content, end="", flush=True) # Add final newline after streaming
full_response["text"] += content print()
# Check if this is an object response (JSON)
if hasattr(chunk, 'object') and chunk.object:
full_response["object"] = chunk.object
# Handle final output
if full_response["text"]:
# Add final newline after streaming text
print()
elif full_response["object"]:
# Print JSON object (pretty-printed)
print(json.dumps(json.loads(full_response["object"]), indent=4))
else: else:
# Non-streaming: handle response # Non-streaming: print complete response
if isinstance(response, str): print(response)
print(response)
elif isinstance(response, dict):
if "text" in response:
print(response["text"])
elif "object" in response:
print(json.dumps(json.loads(response["object"]), indent=4))
finally: finally:
# Clean up socket connection # Clean up socket connection