-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from SamparkAI/fx-restructure-local-toools
feat: restructure, add types in local-tools
- Loading branch information
Showing
49 changed files
with
753 additions
and
792 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,2 @@ | ||
from .action import Action | ||
from .tool import Tool |
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
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 |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
|
||
from .action import Action | ||
|
||
|
||
class Tool: | ||
@property | ||
def tool_name(self) -> str: | ||
|
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 |
---|---|---|
|
@@ -6,5 +6,4 @@ | |
|
||
from .mathematical import Mathematical | ||
|
||
|
||
TOOLS_PATH = Path(__file__).parent |
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,3 +1,4 @@ | ||
""" | ||
File manager. | ||
""" | ||
from .tool import FileTool |
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,2 @@ | ||
from .read_file import ReadFile | ||
from .write_file import WriteFile |
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,50 @@ | ||
import typing as t | ||
from pathlib import Path | ||
from pydantic import BaseModel, Field | ||
from composio.core.local import Action | ||
|
||
class ReadFileRequest(BaseModel): | ||
"""Read file request schema.""" | ||
|
||
base_dir: str = Field( | ||
default=".", | ||
description="Directory where the file will be saved.", | ||
) | ||
filename: str = Field( | ||
..., | ||
description="File name to be saved.", | ||
) | ||
|
||
class ReadFileResponse(BaseModel): | ||
"""Read file response schema.""" | ||
|
||
contents: str = Field( | ||
..., | ||
description="Content read from the file.", | ||
) | ||
|
||
class ReadFile(Action): | ||
"""Read file tool.""" | ||
|
||
_display_name = "Read file" | ||
_description = "Read file from a file." | ||
_request = ReadFileRequest | ||
_response = ReadFileResponse | ||
_tags = ["file", "read"] | ||
_tool_name = "file" | ||
|
||
|
||
def execute(self, request: ReadFileRequest) -> ReadFileResponse: | ||
""" | ||
Reads the contents of the file `file_name` and returns the contents | ||
if successful. | ||
""" | ||
try: | ||
return ReadFileResponse( | ||
contents=Path(request.base_dir, request.filename).read_text( | ||
encoding="utf-8" | ||
) | ||
) | ||
except Exception as e: # pylint: disable=broad-exception-caught | ||
return ReadFileResponse(contents=f"Error reading file: {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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import typing as t | ||
from pathlib import Path | ||
from pydantic import BaseModel, Field | ||
from composio.core.local import Action | ||
|
||
class WriteFileRequest(BaseModel): | ||
"""Safe file request schema.""" | ||
|
||
base_dir: str = Field( | ||
default=".", | ||
description="Directory where the file will be saved.", | ||
) | ||
contents: str = Field( | ||
..., | ||
description="Content to write in the file.", | ||
) | ||
filename: str = Field( | ||
..., | ||
description="File name to be saved.", | ||
) | ||
overwrite: bool = Field( | ||
..., | ||
description="Whether to overwrite a file if it exists or not.", | ||
) | ||
|
||
class WriteFileResponse(BaseModel): | ||
"""Save file response schema.""" | ||
|
||
filename: str = Field( | ||
..., | ||
description="Path of the saved file.", | ||
) | ||
|
||
class WriteFile(Action): | ||
"""Write file tool.""" | ||
|
||
_display_name = "Write file" | ||
_description = "Write file to a file." | ||
_request = WriteFileRequest | ||
_response = WriteFileResponse | ||
_tags = ["file", "write"] | ||
_tool_name = "file" | ||
|
||
def execute(self, request: WriteFileRequest) -> WriteFileResponse: | ||
""" | ||
Saves the contents to a file called `file_name` and returns the | ||
file name if successful. | ||
""" | ||
try: | ||
file = Path(request.base_dir, request.filename) | ||
if not file.parent.exists(): | ||
file.parent.mkdir(parents=True) | ||
if file.exists() and not request.overwrite: | ||
return WriteFileResponse(filename=f"File {file} already exists") | ||
file.write_text(request.contents, encoding="utf-8") | ||
return WriteFileResponse(filename=str(file)) | ||
except Exception as e: # pylint: disable=broad-exception-caught | ||
return WriteFileResponse(filename=f"Error saving to file: {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
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,2 +1 @@ | ||
from .codequery import CodeQuery | ||
from .tool import Greptile |
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 @@ | ||
from .codequery import CodeQuery |
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
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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 +1 @@ | ||
from .cmd_manager_tool import CmdManagerTool | ||
from .tool import CmdManagerTool |
Oops, something went wrong.