Pretty print output

This commit is contained in:
Willem van den Ende 2025-04-30 13:56:13 +01:00
parent f43293819f
commit 86bd32a9e6

View File

@ -1,3 +1,4 @@
import json # Import the json module
from qwen_agent.agents import Assistant
# Define LLM
@ -40,7 +41,15 @@ tools = [
bot = Assistant(llm=llm_cfg, function_list=tools)
# Streaming generation
messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Sumarize the latest developments of Qwen'}]
# Initialize responses variable before the loop in case the loop doesn't run
final_responses = None
for responses in bot.run(messages=messages):
pass
print(responses)
# The loop assigns the latest response to final_responses
final_responses = responses
# Pretty-print the final response object
if final_responses:
print(json.dumps(final_responses, indent=2)) # Use indent=2 (or 4) for pretty printing
else:
print("No response received from the agent.")