Thanh Vinh Vo
commited on
Commit
·
9150700
1
Parent(s):
f4d46a2
update
Browse files- app.py +10 -21
- requirements.txt +1 -2
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import os
|
|
| 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,
|
|
@@ -27,31 +26,21 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 27 |
class BasicAgent:
|
| 28 |
def __init__(self):
|
| 29 |
print("BasicAgent initialized.")
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 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"""
|
| 54 |
-
Answer the following question: `{question}`.
|
|
|
|
| 55 |
"""
|
| 56 |
result = self.agent.run(prompt)
|
| 57 |
print(f"Agent responded with: {result}")
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
import requests
|
|
|
|
| 7 |
from smolagents import (
|
| 8 |
CodeAgent,
|
| 9 |
DuckDuckGoSearchTool,
|
|
|
|
| 26 |
class BasicAgent:
|
| 27 |
def __init__(self):
|
| 28 |
print("BasicAgent initialized.")
|
| 29 |
+
self.agent = CodeAgent(
|
| 30 |
+
tools=[
|
| 31 |
+
VisitWebpageTool(),
|
| 32 |
+
DuckDuckGoSearchTool(),
|
| 33 |
+
],
|
| 34 |
+
model=InferenceClientModel(),
|
| 35 |
+
additional_authorized_imports=["requests", "bs4", "wikipedia"],
|
| 36 |
+
max_steps=20,
|
| 37 |
)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def __call__(self, question: str) -> str:
|
| 40 |
print(f"Agent received question: {question}")
|
| 41 |
prompt = f"""
|
| 42 |
+
Answer the following question: `{question}`. Please follow following rules:
|
| 43 |
+
1. wikipedia Python package is provided to extract data from Wikipedia pages, please use it when possible.
|
| 44 |
"""
|
| 45 |
result = self.agent.run(prompt)
|
| 46 |
print(f"Agent responded with: {result}")
|
requirements.txt
CHANGED
|
@@ -4,5 +4,4 @@ smolagents
|
|
| 4 |
duckduckgo_search
|
| 5 |
bs4
|
| 6 |
markdownify
|
| 7 |
-
|
| 8 |
-
mediawiki-mcp-server
|
|
|
|
| 4 |
duckduckgo_search
|
| 5 |
bs4
|
| 6 |
markdownify
|
| 7 |
+
wikipedia
|
|
|