format
This commit is contained in:
parent
7fa0c78298
commit
acfd344f88
@ -1,4 +1,5 @@
|
||||
import json # Import the json module
|
||||
import json # Import the json module
|
||||
|
||||
from qwen_agent.agents import Assistant
|
||||
|
||||
# Define LLM
|
||||
@ -24,44 +25,44 @@ llm_cfg = {
|
||||
# Define Tools
|
||||
tools = [
|
||||
{'mcpServers': { # You can specify the MCP configuration file
|
||||
'time': {
|
||||
'command': 'uvx',
|
||||
'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
|
||||
},
|
||||
'time': {
|
||||
'command': 'uvx',
|
||||
'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
|
||||
},
|
||||
"fetch": {
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-fetch"]
|
||||
},
|
||||
"ddg-search": {
|
||||
"command": "uvx",
|
||||
"args": ["duckduckgo-mcp-server"]
|
||||
}
|
||||
"ddg-search": {
|
||||
"command": "uvx",
|
||||
"args": ["duckduckgo-mcp-server"]
|
||||
}
|
||||
}
|
||||
},
|
||||
'code_interpreter', # Built-in tools
|
||||
'code_interpreter', # Built-in tools
|
||||
]
|
||||
|
||||
# Define Agent
|
||||
bot = Assistant(llm=llm_cfg, function_list=tools)
|
||||
|
||||
# Streaming generation
|
||||
messages = [{'role': 'user', 'content': 'Write a 500 word blog post about the latest qwen 3 model. Use the search tool, and fetch the top 3 articles before you write the post. Write in a casual, but factual style - no hyperbole. Provide references to the webpages in the output.'}]
|
||||
messages = [{'role': 'user',
|
||||
'content': 'Write a 500 word blog post about the latest qwen 3 model. Use the search tool, and fetch the top 3 articles before you write the post. Write in a casual, but factual style - no hyperbole. Provide references to the webpages in the output.'}]
|
||||
|
||||
final_responses = None
|
||||
# Consider adding error handling around bot.run
|
||||
try:
|
||||
for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000):
|
||||
print(".",end="", flush=True)
|
||||
print(".", end="", flush=True)
|
||||
final_responses = responses.pop()
|
||||
except Exception as e:
|
||||
print(f"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(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
|
||||
print(final_responses.get('content', 'No content found in response.')) # Use .get for safer access
|
||||
else:
|
||||
print("No final response received from the agent.")
|
||||
print("No final response received from the agent.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user