Final_Assignment_Template / tools /file_reader.py
mohammadreza pakzadian
add some useful tools
aa84f48
Raw
History Blame Contribute Delete
530 Bytes
from smolagents import Tool
class FileReader(Tool):
name = 'file_reader'
description = "reads saved files"
inputs = {
"file_path": {
"type": "string",
"description": "path to the file"
}
}
output_type = "string"
def forward(self, file_path: str) -> str:
try:
with open(file_path, "r") as file:
content = file.read()
return content
except Exception as e:
return f'Error in reading file: {str(e)}'