-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make file_read tool framework-agnostic
Co-Authored-By: [email protected] <[email protected]>
- Loading branch information
1 parent
e99eaa1
commit 9933cad
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Framework-agnostic implementation of file reading functionality. | ||
""" | ||
from typing import Optional | ||
from pathlib import Path | ||
|
||
|
||
def read_file(file_path: str) -> str: | ||
"""Read contents of a file at the given path. | ||
Args: | ||
file_path: Path to the file to read | ||
Returns: | ||
str: The contents of the file as a string | ||
Raises: | ||
FileNotFoundError: If the file does not exist | ||
PermissionError: If the file cannot be accessed | ||
Exception: For other file reading errors | ||
""" | ||
try: | ||
path = Path(file_path).resolve() | ||
if not path.exists(): | ||
return f"Error: File not found at path {file_path}" | ||
if not path.is_file(): | ||
return f"Error: Path {file_path} is not a file" | ||
|
||
with open(path, "r", encoding="utf-8") as file: | ||
return file.read() | ||
except (FileNotFoundError, PermissionError, Exception) as e: | ||
return f"Failed to read file {file_path}. Error: {str(e)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"name": "file_read", | ||
"url": "https://github.com/crewAIInc/crewAI-tools/tree/main/crewai_tools/tools/file_read_tool", | ||
"category": "computer-control", | ||
"tools": ["file_read_tool"] | ||
} | ||
"tools": ["read_file"], | ||
"description": "Read contents of files", | ||
"url": "https://github.com/AgentOps-AI/AgentStack/tree/main/agentstack/tools/file_read", | ||
"dependencies": [] | ||
} |
This file was deleted.
Oops, something went wrong.