Thanh Vinh Vo
commited on
Commit
·
f4d46a2
1
Parent(s):
02ee8fe
update
Browse files- app.py +20 -5
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import os
|
|
| 4 |
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
import requests
|
|
|
|
| 7 |
from smolagents import (
|
| 8 |
CodeAgent,
|
| 9 |
DuckDuckGoSearchTool,
|
|
@@ -11,6 +12,7 @@ from smolagents import (
|
|
| 11 |
load_tool,
|
| 12 |
tool,
|
| 13 |
Tool,
|
|
|
|
| 14 |
VisitWebpageTool,
|
| 15 |
)
|
| 16 |
|
|
@@ -26,13 +28,26 @@ class BasicAgent:
|
|
| 26 |
def __init__(self):
|
| 27 |
print("BasicAgent initialized.")
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
max_steps=20,
|
| 34 |
)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def __call__(self, question: str) -> str:
|
| 37 |
print(f"Agent received question: {question}")
|
| 38 |
prompt = f"""
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
import requests
|
| 7 |
+
from mcp import StdioServerParameters
|
| 8 |
from smolagents import (
|
| 9 |
CodeAgent,
|
| 10 |
DuckDuckGoSearchTool,
|
|
|
|
| 12 |
load_tool,
|
| 13 |
tool,
|
| 14 |
Tool,
|
| 15 |
+
ToolCollection,
|
| 16 |
VisitWebpageTool,
|
| 17 |
)
|
| 18 |
|
|
|
|
| 28 |
def __init__(self):
|
| 29 |
print("BasicAgent initialized.")
|
| 30 |
|
| 31 |
+
server_parameters = StdioServerParameters(
|
| 32 |
+
command="uvx",
|
| 33 |
+
args=["--quiet", "mediawiki-mcp-server@0.0.1"],
|
| 34 |
+
env={"UV_PYTHON": "3.12", **os.environ},
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
+
with ToolCollection.from_mcp(
|
| 38 |
+
server_parameters, trust_remote_code=True
|
| 39 |
+
) as tool_collection:
|
| 40 |
+
self.agent = CodeAgent(
|
| 41 |
+
tools=[
|
| 42 |
+
DuckDuckGoSearchTool(),
|
| 43 |
+
VisitWebpageTool(),
|
| 44 |
+
*tool_collection.tools,
|
| 45 |
+
],
|
| 46 |
+
model=InferenceClientModel(),
|
| 47 |
+
additional_authorized_imports=["requests", "bs4"],
|
| 48 |
+
max_steps=20,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
def __call__(self, question: str) -> str:
|
| 52 |
print(f"Agent received question: {question}")
|
| 53 |
prompt = f"""
|
requirements.txt
CHANGED
|
@@ -4,3 +4,5 @@ smolagents
|
|
| 4 |
duckduckgo_search
|
| 5 |
bs4
|
| 6 |
markdownify
|
|
|
|
|
|
|
|
|
| 4 |
duckduckgo_search
|
| 5 |
bs4
|
| 6 |
markdownify
|
| 7 |
+
smolagents[mcp]
|
| 8 |
+
mediawiki-mcp-server
|