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.
|
* `mlx` / `mlx-lm`: Likely used for efficient model inference, especially on Apple Silicon.
|
||||||
* `mcp`: For integrating external tools via the Multi-Agent Collaboration Protocol.
|
* `mcp`: For integrating external tools via the Multi-Agent Collaboration Protocol.
|
||||||
* `python-dotenv`: For managing environment variables (e.g., API keys).
|
* `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.
|
See `pyproject.toml` for the full list of dependencies.
|
||||||
|
|
||||||
@ -77,4 +78,4 @@ This an architectural spike, I welcome your feedback through `qwan.eu/contact`.
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Apache 2.0
|
Apache 2.0
|
||||||
|
@ -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
|
from qwen_agent.agents import Assistant
|
||||||
|
|
||||||
# Define LLM
|
# Define LLM
|
||||||
@ -41,6 +42,7 @@ tools = [
|
|||||||
|
|
||||||
# Define Agent
|
# Define Agent
|
||||||
bot = Assistant(llm=llm_cfg, function_list=tools)
|
bot = Assistant(llm=llm_cfg, function_list=tools)
|
||||||
|
console = Console()
|
||||||
|
|
||||||
# Streaming generation
|
# Streaming generation
|
||||||
messages = [{'role': 'user',
|
messages = [{'role': 'user',
|
||||||
@ -53,17 +55,17 @@ messages = [{'role': 'user',
|
|||||||
final_responses = None
|
final_responses = None
|
||||||
# Consider adding error handling around bot.run
|
# Consider adding error handling around bot.run
|
||||||
try:
|
try:
|
||||||
for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000):
|
with console.status("[bold blue]Thinking...", spinner="dots") as status:
|
||||||
print(".", end="", flush=True)
|
for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000):
|
||||||
final_responses = responses.pop()
|
final_responses = responses.pop()
|
||||||
except Exception as e:
|
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
|
# Pretty-print the final response object
|
||||||
if final_responses:
|
if final_responses:
|
||||||
print("--- Full Response Object ---")
|
console.print("\n[bold green]--- Full Response Object ---[/]")
|
||||||
print(json.dumps(final_responses, indent=2)) # Use indent=2 (or 4) for pretty printing
|
console.print(json.dumps(final_responses, indent=2))
|
||||||
print("\n--- Extracted Content ---")
|
console.print("\n[bold green]--- Extracted Content ---[/]")
|
||||||
print(final_responses.get('content', 'No content found in response.')) # Use .get for safer access
|
console.print(final_responses.get('content', 'No content found in response.'))
|
||||||
else:
|
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-dateutil>=2.9.0.post0",
|
||||||
"python-dotenv>=1.1.0",
|
"python-dotenv>=1.1.0",
|
||||||
"qwen-agent[code-interpreter]>=0.0.20",
|
"qwen-agent[code-interpreter]>=0.0.20",
|
||||||
|
"rich>=13.7.0",
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user