jarvis_gaia_agent / tools /file_parser.py
onisj's picture
Add .gitignore and clean tracked files
1bbca12
raw
history blame
1.46 kB
import pandas as pd
import requests
import os
class FileParserTool:
def __init__(self):
self.name = "file_parser"
self.description = "Downloads and parses CSV or text files for GAIA tasks."
self.inputs = {
"task_id": {"type": "string", "description": "GAIA task ID"},
"file_type": {"type": "string", "description": "File type (csv, txt, default: csv)"}
}
self.output_type = str
async def aparse(self, task_id: str, file_type: str = "csv") -> str:
try:
url = f"https://api.gaia-benchmark.com/files/{task_id}"
response = await requests.get(url)
if response.status_code == 200:
file_path = f"temp_{task_id}.{file_type}"
with open(file_path, "wb") as f:
f.write(response.content)
if file_type == "csv":
df = pd.read_csv(file_path)
return df.to_string()
elif file_type == "txt":
with open(file_path, "r") as f:
return f.read()
else:
return f"Unsupported file type: {file_type}"
return f"Error downloading file for task ID {task_id}"
except Exception as e:
return f"Error: {str(e)}"
finally:
if os.path.exists(file_path):
os.remove(file_path)
file_parser_tool = FileParserTool()