Final_Assignment_Template / tools /read_file_tool.py
shreyassahu22's picture
Upload 10 files
4b58858 verified
Raw
History Blame Contribute Delete
431 Bytes
from langchain.tools import tool
@tool
def read_file_tool(file_path: str) -> str:
"""
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.
"""
try:
with open(file_path, "r") as file:
return file.read()
except Exception as e:
return f"Error reading file: {str(e)}"