Skip to content

Commit

Permalink
Merge pull request #22 from iskandarreza/directory_custom_tools
Browse files Browse the repository at this point in the history
Directory custom tools - CurrentWorkingDir, MakeDirectory
  • Loading branch information
FayazRahman committed Apr 30, 2023
2 parents faedc19 + b44370c commit c3abb3b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions loopgpt/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
DeleteFile,
CheckIfFileExists,
ListFiles,
GetCWD,
MakeDirectory,
FileSystemTools,
)
from loopgpt.tools.shell import Shell
Expand Down
46 changes: 46 additions & 0 deletions loopgpt/tools/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,57 @@ def run(self, path, recursive, show_hidden=False, exclude_dirs=False):
return {"result": entries_list}


class GetCWD(BaseTool):
@property
def args(self):
return {}

@property
def resp(self):
return {"path": "Path to the current working directory"}

@property
def desc(self):
return "Find the current working directory using this command"

def run(self):
try:
cwd = os.getcwd()
return {"path": cwd}
except Exception as e:
return (
f"An error occurred while getting the current working directory: {e}."
)


class MakeDirectory(BaseTool):
@property
def args(self):
return {"path": "Path of the directory to be made"}

@property
def resp(self):
return {"success": "True if the directory was created, False otherwise."}

@property
def desc(self):
return "Make a new directory at the given path"

def run(self, path):
try:
os.makedirs(path)
return {"success": True}
except Exception as e:
return f"An error occurred while creating a new directory path: {e}."


FileSystemTools = [
WriteToFile,
ReadFromFile,
AppendToFile,
DeleteFile,
CheckIfFileExists,
ListFiles,
GetCWD,
MakeDirectory,
]

0 comments on commit c3abb3b

Please sign in to comment.