AlanRocha commited on
Commit
73d1fd0
·
verified ·
1 Parent(s): 4ac6270

Create read_file_tool.py

Browse files
Files changed (1) hide show
  1. tools/read_file_tool.py +26 -0
tools/read_file_tool.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Tool
2
+
3
+ class ReadFileTool(Tool):
4
+ """
5
+ Tool to read a file and return its content.
6
+
7
+ Args:
8
+ file_path (str): Path to the file to read.
9
+
10
+ Returns:
11
+ str: Content of the file or error message.
12
+ """
13
+
14
+ name = "read_file"
15
+ description = "Reads a file and returns its content"
16
+ inputs = {
17
+ "file_path": {"type": "string", "description": "Path to the file to read"},
18
+ }
19
+ output_type = "string"
20
+
21
+ def forward(self, file_path: str) -> str:
22
+ try:
23
+ with open(file_path, "r") as file:
24
+ return file.read()
25
+ except Exception as e:
26
+ return f"Error reading file: {str(e)}"