mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-29 10:26:21 +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:
|
||||
full_response = {"text": "", "object": ""}
|
||||
|
||||
# Stream output
|
||||
# Stream output (prompt yields strings directly)
|
||||
for chunk in response:
|
||||
content = chunk.content
|
||||
if content:
|
||||
print(content, end="", flush=True)
|
||||
full_response["text"] += content
|
||||
|
||||
# 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))
|
||||
if chunk:
|
||||
print(chunk, end="", flush=True)
|
||||
# Add final newline after streaming
|
||||
print()
|
||||
|
||||
else:
|
||||
# Non-streaming: handle response
|
||||
if isinstance(response, str):
|
||||
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))
|
||||
# Non-streaming: print complete response
|
||||
print(response)
|
||||
|
||||
finally:
|
||||
# Clean up socket connection
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue