Spaces:
Running on Zero
Running on Zero
Download tools/read_file_tool.py from Hobysenny/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 683 Bytes
-
https://huggingface.co/spaces/Hobysenny/Final_Assignment_Template/resolve/main/tools/read_file_tool.py
- Command line
-
hf download hf://spaces/Hobysenny/Final_Assignment_Template/tools/read_file_tool.py
-
curl -L -o read_file_tool.py https://huggingface.co/spaces/Hobysenny/Final_Assignment_Template/resolve/main/tools/read_file_tool.py
683 Bytes
| from smolagents import Tool | |
| class ReadFileTool(Tool): | |
| """ | |
| Tool to read a file and return its content. | |
| Args: | |
| file_path (str): Path to the file to read. | |
| Returns: | |
| str: Content of the file or error message. | |
| """ | |
| name = "read_file" | |
| description = "Reads a file and returns its content" | |
| inputs = { | |
| "file_path": {"type": "string", "description": "Path to the file to read"}, | |
| } | |
| output_type = "string" | |
| def forward(self, file_path: str) -> str: | |
| try: | |
| with open(file_path, "r") as file: | |
| return file.read() | |
| except Exception as e: | |
| return f"Error reading file: {str(e)}" | |