Spaces:
Sleeping
Sleeping
Replace Langchain's RequestsGetTool with own tool
Browse filesReplace Langchain's RequestsGetTool with own tool that fetches websites,
to avoid dependency to Langchain.
Add `Returns` fields to doc strings.
app.py
CHANGED
@@ -3,12 +3,27 @@ import requests
|
|
3 |
import pytz
|
4 |
import yaml
|
5 |
|
6 |
-
from
|
7 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel, tool, Tool
|
8 |
from tools.final_answer import FinalAnswerTool
|
9 |
|
10 |
from Gradio_UI import GradioUI
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
@tool
|
13 |
def get_papers_url_for_date(year:int, month:int, day:int)-> str:
|
14 |
"""A tool that constructs a URL where machine learning papers for a specific date (YYYY-MM-DD) are listed.
|
@@ -16,6 +31,8 @@ def get_papers_url_for_date(year:int, month:int, day:int)-> str:
|
|
16 |
year: the year YYYY
|
17 |
month: the month MM
|
18 |
day: the day DD
|
|
|
|
|
19 |
"""
|
20 |
return f"https://huggingface.co/papers?date={year}-{month}-{day}"
|
21 |
|
@@ -24,6 +41,8 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
24 |
"""A tool that fetches the current local time in a specified timezone.
|
25 |
Args:
|
26 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
|
27 |
"""
|
28 |
try:
|
29 |
# Create timezone object
|
@@ -54,7 +73,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
54 |
|
55 |
agent = CodeAgent(
|
56 |
model=model,
|
57 |
-
tools=[final_answer, search_tool,
|
58 |
max_steps=6,
|
59 |
verbosity_level=1,
|
60 |
grammar=None,
|
|
|
3 |
import pytz
|
4 |
import yaml
|
5 |
|
6 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel, tool
|
|
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
11 |
+
@tool
|
12 |
+
def get_website_content(url: str) -> str:
|
13 |
+
"""
|
14 |
+
This tool fetches the content of a website given its URL.
|
15 |
+
Args:
|
16 |
+
url (str): The URL of the website to fetch
|
17 |
+
Returns:
|
18 |
+
str: The content of the website
|
19 |
+
"""
|
20 |
+
try:
|
21 |
+
response = requests.get(url)
|
22 |
+
response.raise_for_status()
|
23 |
+
return response.text
|
24 |
+
except requests.RequestException as e:
|
25 |
+
return f"Error fetching website content: {str(e)}"
|
26 |
+
|
27 |
@tool
|
28 |
def get_papers_url_for_date(year:int, month:int, day:int)-> str:
|
29 |
"""A tool that constructs a URL where machine learning papers for a specific date (YYYY-MM-DD) are listed.
|
|
|
31 |
year: the year YYYY
|
32 |
month: the month MM
|
33 |
day: the day DD
|
34 |
+
Returns:
|
35 |
+
str: The URL where machine learning papers for the specific date are listed.
|
36 |
"""
|
37 |
return f"https://huggingface.co/papers?date={year}-{month}-{day}"
|
38 |
|
|
|
41 |
"""A tool that fetches the current local time in a specified timezone.
|
42 |
Args:
|
43 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
44 |
+
Returns:
|
45 |
+
str: The current local time as `"%Y-%m-%d %H:%M:%S`.
|
46 |
"""
|
47 |
try:
|
48 |
# Create timezone object
|
|
|
73 |
|
74 |
agent = CodeAgent(
|
75 |
model=model,
|
76 |
+
tools=[final_answer, search_tool, get_website_content, get_papers_url_for_date, get_current_time_in_timezone],
|
77 |
max_steps=6,
|
78 |
verbosity_level=1,
|
79 |
grammar=None,
|