Add error handling to see what goes wrong
This commit is contained in:
parent
acfd344f88
commit
8d32e19eb6
@ -33,10 +33,10 @@ tools = [
|
|||||||
"command": "uvx",
|
"command": "uvx",
|
||||||
"args": ["mcp-server-fetch"]
|
"args": ["mcp-server-fetch"]
|
||||||
},
|
},
|
||||||
"ddg-search": {
|
"ddg-search": {
|
||||||
"command": "uvx",
|
"command": "npx",
|
||||||
"args": ["duckduckgo-mcp-server"]
|
"args": ["-y", "@oevortex/ddg_search"]
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'code_interpreter', # Built-in tools
|
'code_interpreter', # Built-in tools
|
||||||
@ -47,22 +47,59 @@ bot = Assistant(llm=llm_cfg, function_list=tools)
|
|||||||
|
|
||||||
# Streaming generation
|
# Streaming generation
|
||||||
messages = [{'role': 'user',
|
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.'}]
|
'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 urls to the webpages in the output."""}]
|
||||||
|
|
||||||
final_responses = None
|
final_responses = None
|
||||||
# Consider adding error handling around bot.run
|
# Add comprehensive error handling around bot.run
|
||||||
try:
|
try:
|
||||||
for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000):
|
timeout = 300 # 5 minute timeout
|
||||||
print(".", end="", flush=True)
|
final_responses = None
|
||||||
final_responses = responses.pop()
|
partial_responses = []
|
||||||
except Exception as e:
|
|
||||||
print(f"An error occurred during agent execution: {e}")
|
|
||||||
|
|
||||||
# Pretty-print the final response object
|
for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000, timeout=timeout):
|
||||||
|
print(".", end="", flush=True)
|
||||||
|
partial_responses.append(responses)
|
||||||
|
final_responses = responses.pop()
|
||||||
|
|
||||||
|
except TimeoutError:
|
||||||
|
print("\nRequest timed out after {} seconds".format(timeout))
|
||||||
|
except ConnectionError as ce:
|
||||||
|
print(f"\nConnection error occurred: {ce}")
|
||||||
|
except ValueError as ve:
|
||||||
|
print(f"\nInvalid input or response format: {ve}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\nAn unexpected error occurred: {e}")
|
||||||
|
finally:
|
||||||
|
if partial_responses and not final_responses:
|
||||||
|
try:
|
||||||
|
final_responses = partial_responses[-1].pop()
|
||||||
|
except (IndexError, AttributeError):
|
||||||
|
print("\nFailed to recover partial response")
|
||||||
|
|
||||||
|
# Pretty-print the final response object with validation
|
||||||
if final_responses:
|
if final_responses:
|
||||||
print("--- Full Response Object ---")
|
print("\n--- Full Response Object ---")
|
||||||
print(json.dumps(final_responses, indent=2)) # Use indent=2 (or 4) for pretty printing
|
try:
|
||||||
print("\n--- Extracted Content ---")
|
if isinstance(final_responses, dict):
|
||||||
print(final_responses.get('content', 'No content found in response.')) # Use .get for safer access
|
print(json.dumps(final_responses, indent=2))
|
||||||
|
else:
|
||||||
|
print("Response is not in expected format:", type(final_responses))
|
||||||
|
|
||||||
|
print("\n--- Extracted Content ---")
|
||||||
|
if isinstance(final_responses, dict):
|
||||||
|
content = final_responses.get('content')
|
||||||
|
if content:
|
||||||
|
print(content)
|
||||||
|
else:
|
||||||
|
print("No content field found in response")
|
||||||
|
else:
|
||||||
|
print("Cannot extract content from invalid response format")
|
||||||
|
except json.JSONDecodeError as je:
|
||||||
|
print(f"Failed to format response: {je}")
|
||||||
else:
|
else:
|
||||||
print("No final response received from the agent.")
|
print("\nNo final response received from the agent.")
|
||||||
|
@ -5,7 +5,6 @@ description = "Add your description here"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"duckduckgo-mcp-server>=0.1.1",
|
|
||||||
"mcp>=1.6.0",
|
"mcp>=1.6.0",
|
||||||
"mlx>=0.25.1",
|
"mlx>=0.25.1",
|
||||||
"mlx-lm>=0.24.0",
|
"mlx-lm>=0.24.0",
|
||||||
|
80
uv.lock
generated
80
uv.lock
generated
@ -378,20 +378,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/12/b3/231ffd4ab1fc9d679809f356cebee130ac7daa00d6d6f3206dd4fd137e9e/distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2", size = 20277 },
|
{ url = "https://files.pythonhosted.org/packages/12/b3/231ffd4ab1fc9d679809f356cebee130ac7daa00d6d6f3206dd4fd137e9e/distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2", size = 20277 },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "duckduckgo-mcp-server"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "beautifulsoup4" },
|
|
||||||
{ name = "httpx" },
|
|
||||||
{ name = "mcp", extra = ["cli"] },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/86/82/ad813d88199de0a88aa50536e569f6191da572a6d5bf2e7fcccb7e28b522/duckduckgo_mcp_server-0.1.1.tar.gz", hash = "sha256:d6f48f4cb4234de9e716e87f7d49aa54637ebc4a3700ecfd05f260696463c0ec", size = 19920 }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/c6/42/e7d7fc70744d3ebf7b309a19176bb745c5e7d5babf77fcf903068cb08bbd/duckduckgo_mcp_server-0.1.1-py3-none-any.whl", hash = "sha256:ca56c67bcfcef259ce083d1700700f5b66f75a48b4c1e13f556289cf3351b50b", size = 6520 },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "eval-type-backport"
|
name = "eval-type-backport"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@ -1030,18 +1016,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/4c/fa/be89a49c640930180657482a74970cdcf6f7072c8d2471e1babe17a222dc/kiwisolver-1.4.8-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:be4816dc51c8a471749d664161b434912eee82f2ea66bd7628bd14583a833e85", size = 2349213 },
|
{ url = "https://files.pythonhosted.org/packages/4c/fa/be89a49c640930180657482a74970cdcf6f7072c8d2471e1babe17a222dc/kiwisolver-1.4.8-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:be4816dc51c8a471749d664161b434912eee82f2ea66bd7628bd14583a833e85", size = 2349213 },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "markdown-it-py"
|
|
||||||
version = "3.0.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "mdurl" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/38/71/3b932df36c1a044d397a1f92d1cf91ee0a503d91e470cbd670aa66b07ed0/markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb", size = 74596 }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/42/d7/1ec15b46af6af88f19b8e5ffea08fa375d433c998b8a7639e76935c14f1f/markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1", size = 87528 },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "markupsafe"
|
name = "markupsafe"
|
||||||
version = "3.0.2"
|
version = "3.0.2"
|
||||||
@ -1132,21 +1106,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/10/30/20a7f33b0b884a9d14dd3aa94ff1ac9da1479fe2ad66dd9e2736075d2506/mcp-1.6.0-py3-none-any.whl", hash = "sha256:7bd24c6ea042dbec44c754f100984d186620d8b841ec30f1b19eda9b93a634d0", size = 76077 },
|
{ url = "https://files.pythonhosted.org/packages/10/30/20a7f33b0b884a9d14dd3aa94ff1ac9da1479fe2ad66dd9e2736075d2506/mcp-1.6.0-py3-none-any.whl", hash = "sha256:7bd24c6ea042dbec44c754f100984d186620d8b841ec30f1b19eda9b93a634d0", size = 76077 },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.optional-dependencies]
|
|
||||||
cli = [
|
|
||||||
{ name = "python-dotenv" },
|
|
||||||
{ name = "typer" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mdurl"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729 }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979 },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mistune"
|
name = "mistune"
|
||||||
version = "3.1.3"
|
version = "3.1.3"
|
||||||
@ -1826,7 +1785,6 @@ name = "qwen3"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = { virtual = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "duckduckgo-mcp-server" },
|
|
||||||
{ name = "mcp" },
|
{ name = "mcp" },
|
||||||
{ name = "mlx" },
|
{ name = "mlx" },
|
||||||
{ name = "mlx-lm" },
|
{ name = "mlx-lm" },
|
||||||
@ -1837,7 +1795,6 @@ dependencies = [
|
|||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "duckduckgo-mcp-server", specifier = ">=0.1.1" },
|
|
||||||
{ name = "mcp", specifier = ">=1.6.0" },
|
{ name = "mcp", specifier = ">=1.6.0" },
|
||||||
{ name = "mlx", specifier = ">=0.25.1" },
|
{ name = "mlx", specifier = ">=0.25.1" },
|
||||||
{ name = "mlx-lm", specifier = ">=0.24.0" },
|
{ name = "mlx-lm", specifier = ">=0.24.0" },
|
||||||
@ -1918,19 +1875,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/9e/51/17023c0f8f1869d8806b979a2bffa3f861f26a3f1a66b094288323fba52f/rfc3986_validator-0.1.1-py2.py3-none-any.whl", hash = "sha256:2f235c432ef459970b4306369336b9d5dbdda31b510ca1e327636e01f528bfa9", size = 4242 },
|
{ url = "https://files.pythonhosted.org/packages/9e/51/17023c0f8f1869d8806b979a2bffa3f861f26a3f1a66b094288323fba52f/rfc3986_validator-0.1.1-py2.py3-none-any.whl", hash = "sha256:2f235c432ef459970b4306369336b9d5dbdda31b510ca1e327636e01f528bfa9", size = 4242 },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rich"
|
|
||||||
version = "14.0.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "markdown-it-py" },
|
|
||||||
{ name = "pygments" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/a1/53/830aa4c3066a8ab0ae9a9955976fb770fe9c6102117c8ec4ab3ea62d89e8/rich-14.0.0.tar.gz", hash = "sha256:82f1bc23a6a21ebca4ae0c45af9bdbc492ed20231dcb63f297d6d1021a9d5725", size = 224078 }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/0d/9b/63f4c7ebc259242c89b3acafdb37b41d1185c07ff0011164674e9076b491/rich-14.0.0-py3-none-any.whl", hash = "sha256:1c9491e1951aac09caffd42f448ee3d04e58923ffe14993f6e83068dc395d7e0", size = 243229 },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rpds-py"
|
name = "rpds-py"
|
||||||
version = "0.24.0"
|
version = "0.24.0"
|
||||||
@ -2025,15 +1969,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/2a/8e/2ee81652472f3c11503d1780c41844a9a9656989b69c29811a4631e4aeb9/setuptools-80.0.1-py3-none-any.whl", hash = "sha256:f4b49d457765b3aae7cbbeb1c71f6633a61b729408c2d1a837dae064cca82ef2", size = 1240915 },
|
{ url = "https://files.pythonhosted.org/packages/2a/8e/2ee81652472f3c11503d1780c41844a9a9656989b69c29811a4631e4aeb9/setuptools-80.0.1-py3-none-any.whl", hash = "sha256:f4b49d457765b3aae7cbbeb1c71f6633a61b729408c2d1a837dae064cca82ef2", size = 1240915 },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shellingham"
|
|
||||||
version = "1.5.4"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/58/15/8b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e/shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de", size = 10310 }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755 },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "six"
|
name = "six"
|
||||||
version = "1.17.0"
|
version = "1.17.0"
|
||||||
@ -2247,21 +2182,6 @@ sentencepiece = [
|
|||||||
{ name = "sentencepiece" },
|
{ name = "sentencepiece" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typer"
|
|
||||||
version = "0.15.3"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "click" },
|
|
||||||
{ name = "rich" },
|
|
||||||
{ name = "shellingham" },
|
|
||||||
{ name = "typing-extensions" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/98/1a/5f36851f439884bcfe8539f6a20ff7516e7b60f319bbaf69a90dc35cc2eb/typer-0.15.3.tar.gz", hash = "sha256:818873625d0569653438316567861899f7e9972f2e6e0c16dab608345ced713c", size = 101641 }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/48/20/9d953de6f4367163d23ec823200eb3ecb0050a2609691e512c8b95827a9b/typer-0.15.3-py3-none-any.whl", hash = "sha256:c86a65ad77ca531f03de08d1b9cb67cd09ad02ddddf4b34745b5008f43b239bd", size = 45253 },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "types-python-dateutil"
|
name = "types-python-dateutil"
|
||||||
version = "2.9.0.20241206"
|
version = "2.9.0.20241206"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user