Thomas Bartlett
commited on
Commit
·
d8b4697
1
Parent(s):
2890651
use the annotation for tool
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
-
from langchain_core.tools import
|
| 5 |
import requests, textwrap
|
| 6 |
|
| 7 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
|
@@ -36,31 +36,29 @@ Adhere strictly to these rules:
|
|
| 36 |
Begin.
|
| 37 |
"""
|
| 38 |
|
| 39 |
-
|
| 40 |
-
""
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
"""
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# ---- sync path (we don't need async) ------------------
|
| 53 |
-
def _run(self, task_id: str, run_manager=None) -> str:
|
| 54 |
-
url = f"https://{GAIA_HOST}/files/{task_id}"
|
| 55 |
-
resp = requests.get(url, timeout=15)
|
| 56 |
-
if resp.status_code != 200:
|
| 57 |
-
return f"ERROR {resp.status_code}: could not fetch file."
|
| 58 |
-
ctype = resp.headers.get("content-type", "")
|
| 59 |
-
# naive check: treat anything text/* or json/csv as text
|
| 60 |
-
if "text" in ctype or "json" in ctype or "csv" in ctype:
|
| 61 |
-
text = resp.text[:20_000]
|
| 62 |
-
return text
|
| 63 |
-
return f"[binary file {ctype} of {len(resp.content)} bytes downloaded]"
|
| 64 |
|
| 65 |
|
| 66 |
class BasicAgent:
|
|
@@ -78,7 +76,7 @@ class BasicAgent:
|
|
| 78 |
)
|
| 79 |
|
| 80 |
tools = [
|
| 81 |
-
|
| 82 |
DuckDuckGoSearchRun(),
|
| 83 |
]
|
| 84 |
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
+
from langchain_core.tools import tool
|
| 5 |
import requests, textwrap
|
| 6 |
|
| 7 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
|
|
|
| 36 |
Begin.
|
| 37 |
"""
|
| 38 |
|
| 39 |
+
@tool(
|
| 40 |
+
name="gaia_file_fetch",
|
| 41 |
+
description=textwrap.dedent(
|
| 42 |
+
"""\
|
| 43 |
+
Download the file attached to a GAIA task.
|
| 44 |
+
• Input: task_id (string)
|
| 45 |
+
• Output: text content (truncated to 20 000 chars) or a notice for binary files.
|
| 46 |
+
"""
|
| 47 |
+
),
|
| 48 |
+
)
|
| 49 |
+
def gaia_file_fetch(task_id: str) -> str:
|
| 50 |
+
"""Sync helper the agent can call."""
|
| 51 |
+
url = f"https://{GAIA_HOST}/files/{task_id}"
|
| 52 |
+
resp = requests.get(url, timeout=15)
|
| 53 |
|
| 54 |
+
if resp.status_code != 200:
|
| 55 |
+
return f"ERROR {resp.status_code}: could not fetch file."
|
| 56 |
+
|
| 57 |
+
ctype = resp.headers.get("content-type", "")
|
| 58 |
+
if any(t in ctype for t in ("text", "json", "csv")):
|
| 59 |
+
return resp.text[:20_000]
|
| 60 |
+
|
| 61 |
+
return f"[binary file {ctype} of {len(resp.content)} bytes downloaded]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
class BasicAgent:
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
tools = [
|
| 79 |
+
gaia_file_fetch,
|
| 80 |
DuckDuckGoSearchRun(),
|
| 81 |
]
|
| 82 |
|