mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-05-01 19:32:38 +02:00
Fixing invoke_prompt
This commit is contained in:
parent
31494d14e1
commit
75eb02e546
1 changed files with 7 additions and 27 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue