# Libs import os import requests import pandas as pd from smolagents import Tool # Local from consts import DEFAULT_API_URL class GetTaskFileTool(Tool): name = "get_task_file_tool" description = """This tool downloads the file content associated with the given task_id if exists. Returns absolute file path""" inputs = { "task_id": {"type": "string", "description": "Task id"}, "file_name": {"type": "string", "description": "File name"}, } output_type = "string" def forward(self, task_id: str, file_name: str) -> str: response = requests.get(f"{DEFAULT_API_URL}/files/{task_id}", timeout=15) response.raise_for_status() with open(file_name, 'wb') as file: file.write(response.content) return os.path.abspath(file_name) class LoadXlsxFileTool(Tool): name = "load_xlsx_file_tool" description = """This tool loads xlsx file into pandas and returns it""" inputs = { "file_path": {"type": "string", "description": "File path"} } output_type = "object" def forward(self, file_path: str) -> object: return pd.read_excel(file_path) class LoadTextFileTool(Tool): name = "load_text_file_tool" description = """This tool loads any text file""" inputs = { "file_path": {"type": "string", "description": "File path"} } output_type = "string" def forward(self, file_path: str) -> object: with open(file_path, 'r', encoding='utf-8') as file: return file.read()