Spaces:
Sleeping
Sleeping
Thomas Bartlett
commited on
Commit
·
fc8b565
1
Parent(s):
9b20450
add Calculator tool to BasicAgent and update requirements
Browse files- app.py +9 -4
- requirements.txt +1 -1
app.py
CHANGED
@@ -6,9 +6,11 @@ import requests, textwrap
|
|
6 |
|
7 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
8 |
|
9 |
-
from langchain_community.tools import DuckDuckGoSearchRun
|
10 |
-
from langchain.agents import initialize_agent
|
11 |
from langchain_core.prompts import ChatPromptTemplate
|
|
|
|
|
12 |
|
13 |
# --- Constants ---
|
14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
@@ -23,6 +25,7 @@ You are GAIA-Bot, a fully-autonomous problem-solver.
|
|
23 |
You have access to these tools:
|
24 |
- gaia_file_fetch – download the file attached to the current task_id.
|
25 |
- duckduckgo_search – look up current facts on the public web.
|
|
|
26 |
|
27 |
If you require a file attached to the current task, download it with
|
28 |
`requests_get("https://agents-course-unit4-scoring.hf.space/files/{task_id}")`
|
@@ -44,7 +47,7 @@ def gaia_file_fetch(task_id: str) -> str:
|
|
44 |
• Input: task_id (string)
|
45 |
• Output: text content (first 20 000 chars) or a notice if the file is binary.
|
46 |
"""
|
47 |
-
url = f"https://{
|
48 |
resp = requests.get(url, timeout=15)
|
49 |
if resp.status_code != 200:
|
50 |
return f"ERROR {resp.status_code}: could not fetch file."
|
@@ -74,6 +77,7 @@ class BasicAgent:
|
|
74 |
tools = [
|
75 |
gaia_file_fetch,
|
76 |
DuckDuckGoSearchRun(),
|
|
|
77 |
]
|
78 |
|
79 |
prompt = ChatPromptTemplate.from_messages([
|
@@ -85,7 +89,8 @@ class BasicAgent:
|
|
85 |
tools=tools,
|
86 |
llm=self.llm,
|
87 |
prompt=prompt,
|
88 |
-
max_iterations=
|
|
|
89 |
verbose=False,
|
90 |
)
|
91 |
|
|
|
6 |
|
7 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
8 |
|
9 |
+
from langchain_community.tools import DuckDuckGoSearchRun, Calculator
|
10 |
+
from langchain.agents import initialize_agent
|
11 |
from langchain_core.prompts import ChatPromptTemplate
|
12 |
+
from langchain_community.tools import Calculator
|
13 |
+
|
14 |
|
15 |
# --- Constants ---
|
16 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
25 |
You have access to these tools:
|
26 |
- gaia_file_fetch – download the file attached to the current task_id.
|
27 |
- duckduckgo_search – look up current facts on the public web.
|
28 |
+
- calculator – evaluate math expressions, percentages, date differences.
|
29 |
|
30 |
If you require a file attached to the current task, download it with
|
31 |
`requests_get("https://agents-course-unit4-scoring.hf.space/files/{task_id}")`
|
|
|
47 |
• Input: task_id (string)
|
48 |
• Output: text content (first 20 000 chars) or a notice if the file is binary.
|
49 |
"""
|
50 |
+
url = f"https://{DEFAULT_API_URL}/files/{task_id}"
|
51 |
resp = requests.get(url, timeout=15)
|
52 |
if resp.status_code != 200:
|
53 |
return f"ERROR {resp.status_code}: could not fetch file."
|
|
|
77 |
tools = [
|
78 |
gaia_file_fetch,
|
79 |
DuckDuckGoSearchRun(),
|
80 |
+
Calculator()
|
81 |
]
|
82 |
|
83 |
prompt = ChatPromptTemplate.from_messages([
|
|
|
89 |
tools=tools,
|
90 |
llm=self.llm,
|
91 |
prompt=prompt,
|
92 |
+
max_iterations=15,
|
93 |
+
max_execution_time=120, # seconds
|
94 |
verbose=False,
|
95 |
)
|
96 |
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
langchain
|
2 |
langchain-huggingface
|
3 |
-
langchain-community # for DuckDuckGoSearchRun
|
4 |
huggingface-hub
|
5 |
duckduckgo-search
|
6 |
gradio
|
|
|
1 |
langchain
|
2 |
langchain-huggingface
|
3 |
+
langchain-community # for DuckDuckGoSearchRun, Calculator
|
4 |
huggingface-hub
|
5 |
duckduckgo-search
|
6 |
gradio
|