Spaces:
Sleeping
Sleeping
Thomas Bartlett
commited on
Commit
·
36df13f
1
Parent(s):
314a50a
just create a tool for the api
Browse files- app.py +29 -4
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import pandas as pd
|
|
| 5 |
|
| 6 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
| 7 |
|
| 8 |
-
from langchain.tools import RequestsGetTool
|
| 9 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 10 |
from langchain.agents import initialize_agent, AgentType
|
| 11 |
from langchain_core.prompts import ChatPromptTemplate
|
|
@@ -21,8 +20,8 @@ You are GAIA-Bot, a fully-autonomous problem-solver.
|
|
| 21 |
• After finishing all reasoning, RESPOND with **only** the final answer string—no pre-amble, no labels, no extra text.
|
| 22 |
|
| 23 |
You have access to these tools:
|
| 24 |
-
-
|
| 25 |
-
- duckduckgo_search
|
| 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}")`
|
|
@@ -36,6 +35,32 @@ Adhere strictly to these rules:
|
|
| 36 |
Begin.
|
| 37 |
"""
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
class BasicAgent:
|
| 41 |
def __init__(self):
|
|
@@ -52,7 +77,7 @@ class BasicAgent:
|
|
| 52 |
)
|
| 53 |
|
| 54 |
tools = [
|
| 55 |
-
|
| 56 |
DuckDuckGoSearchRun(),
|
| 57 |
]
|
| 58 |
|
|
|
|
| 5 |
|
| 6 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
| 7 |
|
|
|
|
| 8 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 9 |
from langchain.agents import initialize_agent, AgentType
|
| 10 |
from langchain_core.prompts import ChatPromptTemplate
|
|
|
|
| 20 |
• After finishing all reasoning, RESPOND with **only** the final answer string—no pre-amble, no labels, no extra text.
|
| 21 |
|
| 22 |
You have access to these tools:
|
| 23 |
+
- gaia_file_fetch – download the file attached to the current task_id.
|
| 24 |
+
- duckduckgo_search – look up current facts on the public web.
|
| 25 |
|
| 26 |
If you require a file attached to the current task, download it with
|
| 27 |
`requests_get("https://agents-course-unit4-scoring.hf.space/files/{task_id}")`
|
|
|
|
| 35 |
Begin.
|
| 36 |
"""
|
| 37 |
|
| 38 |
+
class ScoringFileTool(BaseTool):
|
| 39 |
+
"""
|
| 40 |
+
Download the file attached to a GAIA question.
|
| 41 |
+
|
| 42 |
+
Input: the task_id string.
|
| 43 |
+
Output: the (text) content, truncated to 20 000 chars.
|
| 44 |
+
If the file is binary (e.g. PDF, image) return a notice instead.
|
| 45 |
+
"""
|
| 46 |
+
name = "gaia_file_fetch"
|
| 47 |
+
description = textwrap.dedent(f"""\
|
| 48 |
+
Use this to download the file for a GAIA task when the question
|
| 49 |
+
mentions an attachment. Input MUST be the task_id.""")
|
| 50 |
+
|
| 51 |
+
# ---- sync path (we don't need async) ------------------
|
| 52 |
+
def _run(self, task_id: str, run_manager=None) -> str:
|
| 53 |
+
url = f"https://{GAIA_HOST}/files/{task_id}"
|
| 54 |
+
resp = requests.get(url, timeout=15)
|
| 55 |
+
if resp.status_code != 200:
|
| 56 |
+
return f"ERROR {resp.status_code}: could not fetch file."
|
| 57 |
+
ctype = resp.headers.get("content-type", "")
|
| 58 |
+
# naive check: treat anything text/* or json/csv as text
|
| 59 |
+
if "text" in ctype or "json" in ctype or "csv" in ctype:
|
| 60 |
+
text = resp.text[:20_000]
|
| 61 |
+
return text
|
| 62 |
+
return f"[binary file {ctype} of {len(resp.content)} bytes downloaded]"
|
| 63 |
+
|
| 64 |
|
| 65 |
class BasicAgent:
|
| 66 |
def __init__(self):
|
|
|
|
| 77 |
)
|
| 78 |
|
| 79 |
tools = [
|
| 80 |
+
ScoringFileTool(),
|
| 81 |
DuckDuckGoSearchRun(),
|
| 82 |
]
|
| 83 |
|
requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
langchain
|
| 2 |
langchain-huggingface
|
|
|
|
| 3 |
huggingface-hub
|
| 4 |
duckduckgo-search
|
| 5 |
gradio
|
| 6 |
pandas
|
| 7 |
requests
|
| 8 |
-
langchain-community
|
|
|
|
| 1 |
langchain
|
| 2 |
langchain-huggingface
|
| 3 |
+
langchain-community # for DuckDuckGoSearchRun
|
| 4 |
huggingface-hub
|
| 5 |
duckduckgo-search
|
| 6 |
gradio
|
| 7 |
pandas
|
| 8 |
requests
|
|
|