FileReadTool
Reads a file and returns its contents.
Parameters
file_path
(str): The path to the file to be read.encoding
(str, optional): The encoding of the file, defaults to utf-8.
Returns
The return value is of the type: ToolReturn
(Learn more about:
ToolReturn) with the following output and
exit_code:
output
(str): The contents of the file.exit_code
(int): 0 if success, 1 if failure.
Usage
(Learn more about: FileWriteTool)
import asyncio
from embedia.tools import FileWriteTool, FileReadTool
file_writer = FileWriteTool()
file_reader = FileReadTool()
asyncio.run(file_writer(file_path="test.txt", content="Hello World!"))
resp = asyncio.run(file_reader(file_path="test.txt"))
print("Contents of text.txt:", resp.output)
Running the above code prints the following:
[time: 2023-10-03T09:27:48.801571+00:00] [id: 139971103827792] [event: Tool Start]
Tool: FileWriteTool
Args: ()
Kwargs: {'file_path': 'test.txt', 'content': 'Hello World!'}
[time: 2023-10-03T09:27:48.801812+00:00] [id: 139971103827792] [event: Tool End]
Tool: FileWriteTool
ExitCode: 0
Output:
12
[time: 2023-10-03T09:27:48.802660+00:00] [id: 139971103818768] [event: Tool Start]
Tool: FileReadTool
Args: ()
Kwargs: {'file_path': 'test.txt'}
[time: 2023-10-03T09:27:48.802780+00:00] [id: 139971103818768] [event: Tool End]
Tool: FileReadTool
ExitCode: 0
Output:
Hello World!
Contents of text.txt: Hello World!