Spaces:
Runtime error
Runtime error
Commit
·
5b9240c
1
Parent(s):
d35385e
Add try block
Browse files
app.py
CHANGED
@@ -5,22 +5,28 @@ from smolagents import ToolCollection, CodeAgent
|
|
5 |
from smolagents import CodeAgent, InferenceClientModel
|
6 |
from smolagents.mcp_client import MCPClient
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
demo = gr.ChatInterface(
|
18 |
-
fn=lambda message, history: str(agent.run(message)),
|
19 |
-
type="messages",
|
20 |
-
examples=["Prime factorization of 68"],
|
21 |
-
title="Agent with MCP Tools",
|
22 |
-
description="This is a simple agent that uses MCP tools to answer questions.",
|
23 |
-
messages=[],
|
24 |
-
)
|
25 |
|
26 |
-
demo.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from smolagents import CodeAgent, InferenceClientModel
|
6 |
from smolagents.mcp_client import MCPClient
|
7 |
|
8 |
+
try:
|
9 |
+
mcp_client = MCPClient(
|
10 |
+
{"url": "http://localhost:7860/gradio_api/mcp/sse"}
|
11 |
+
)
|
12 |
+
tools = mcp_client.get_tools()
|
13 |
|
14 |
+
model = InferenceClientModel()
|
15 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
16 |
|
17 |
+
def call_agent(message, history):
|
18 |
+
return str(agent.run(message))
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
demo = gr.ChatInterface(
|
22 |
+
fn=lambda message, history: str(agent.run(message)),
|
23 |
+
type="messages",
|
24 |
+
examples=["Prime factorization of 68"],
|
25 |
+
title="Agent with MCP Tools",
|
26 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
27 |
+
messages=[],
|
28 |
+
)
|
29 |
+
|
30 |
+
demo.launch()
|
31 |
+
finally:
|
32 |
+
mcp_client.close()
|