feat: add rich spinner for improved terminal progress indication
This commit is contained in:
parent
5a9932a1e7
commit
e2f6f4e15a
@ -68,6 +68,7 @@ Key Python libraries used:
|
||||
* `mlx` / `mlx-lm`: Likely used for efficient model inference, especially on Apple Silicon.
|
||||
* `mcp`: For integrating external tools via the Multi-Agent Collaboration Protocol.
|
||||
* `python-dotenv`: For managing environment variables (e.g., API keys).
|
||||
* `rich`: For beautiful terminal formatting and progress indicators.
|
||||
|
||||
See `pyproject.toml` for the full list of dependencies.
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import json # Import the json module
|
||||
|
||||
import json
|
||||
from rich.console import Console
|
||||
from rich.spinner import Spinner
|
||||
from qwen_agent.agents import Assistant
|
||||
|
||||
# Define LLM
|
||||
@ -41,6 +42,7 @@ tools = [
|
||||
|
||||
# Define Agent
|
||||
bot = Assistant(llm=llm_cfg, function_list=tools)
|
||||
console = Console()
|
||||
|
||||
# Streaming generation
|
||||
messages = [{'role': 'user',
|
||||
@ -53,17 +55,17 @@ messages = [{'role': 'user',
|
||||
final_responses = None
|
||||
# Consider adding error handling around bot.run
|
||||
try:
|
||||
with console.status("[bold blue]Thinking...", spinner="dots") as status:
|
||||
for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000):
|
||||
print(".", end="", flush=True)
|
||||
final_responses = responses.pop()
|
||||
except Exception as e:
|
||||
print(f"An error occurred during agent execution: {e}")
|
||||
console.print(f"[bold red]An error occurred during agent execution:[/] {e}")
|
||||
|
||||
# Pretty-print the final response object
|
||||
if final_responses:
|
||||
print("--- Full Response Object ---")
|
||||
print(json.dumps(final_responses, indent=2)) # Use indent=2 (or 4) for pretty printing
|
||||
print("\n--- Extracted Content ---")
|
||||
print(final_responses.get('content', 'No content found in response.')) # Use .get for safer access
|
||||
console.print("\n[bold green]--- Full Response Object ---[/]")
|
||||
console.print(json.dumps(final_responses, indent=2))
|
||||
console.print("\n[bold green]--- Extracted Content ---[/]")
|
||||
console.print(final_responses.get('content', 'No content found in response.'))
|
||||
else:
|
||||
print("No final response received from the agent.")
|
||||
console.print("[bold red]No final response received from the agent.[/]")
|
||||
|
@ -11,4 +11,5 @@ dependencies = [
|
||||
"python-dateutil>=2.9.0.post0",
|
||||
"python-dotenv>=1.1.0",
|
||||
"qwen-agent[code-interpreter]>=0.0.20",
|
||||
"rich>=13.7.0",
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user