From 279f67f78fe2e4e37ea6e302c495eadff656e836 Mon Sep 17 00:00:00 2001 From: Iskandar Reza Date: Fri, 28 Apr 2023 01:31:18 -0700 Subject: [PATCH 1/5] Create directory_tools.py --- directory_tools.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 directory_tools.py diff --git a/directory_tools.py b/directory_tools.py new file mode 100644 index 0000000..1303c12 --- /dev/null +++ b/directory_tools.py @@ -0,0 +1,85 @@ +from loopgpt.tools import BaseTool +import os + +class CurrentWorkingDir(BaseTool): + @property + def args(self): + return {} + + @property + def resp(self): + return {"report": "The current working directory"} + + @property + def id(self): + return "current_directory" + + @property + def desc(self): + return "The current working directory/folder" + + def run(self): + try: + data = os.getcwd() + data = {"report": data} + return data + except Exception as e: + return {"report": f"An error occurred while getting the current working directory: {e}."} + +class ListDirectories(BaseTool): + @property + def args(self): + return {"path": "path/to/directory"} + + @property + def resp(self): + return {"report": "The list of directories in the path"} + + @property + def id(self): + return "list_directories" + + @property + def desc(self): + return "List directories in a given path" + + def run(self, path): + try: + data = [f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))] + data = {"report": data} + return data + except Exception as e: + return {"report": f"An error occurred while getting directories list: {e}."} + +class MakeDirectory(BaseTool): + @property + def args(self): + return {"newpath": "path/to/directory"} + + @property + def resp(self): + return {"report": "The path to the directory to be made"} + + @property + def id(self): + return "make_dir" + + @property + def desc(self): + return "Make a directory/folder to the given path" + + def run(self, newpath): + try: + def make_dir(newdirpath): + if not os.path.isdir(newdirpath): + os.makedirs(newdirpath) + make_dir(newpath) + return {"report": f"Directory '{newpath}' was created" } + except Exception as e: + return {"report": f"An error occurred while creating a new directory path: {e}."} + +DirectoryTools = [ + CurrentWorkingDir, + ListDirectories, + MakeDirectory +] \ No newline at end of file From ae5d068ab470f693883ac6c8950d763df09e99e6 Mon Sep 17 00:00:00 2001 From: Iskandar Reza Date: Sat, 29 Apr 2023 18:50:52 -0700 Subject: [PATCH 2/5] cleanup --- .../directory_tools.py | 26 ------------------- 1 file changed, 26 deletions(-) rename directory_tools.py => addons/directory_tools.py (67%) diff --git a/directory_tools.py b/addons/directory_tools.py similarity index 67% rename from directory_tools.py rename to addons/directory_tools.py index 1303c12..92a5f05 100644 --- a/directory_tools.py +++ b/addons/directory_tools.py @@ -25,31 +25,6 @@ def run(self): return data except Exception as e: return {"report": f"An error occurred while getting the current working directory: {e}."} - -class ListDirectories(BaseTool): - @property - def args(self): - return {"path": "path/to/directory"} - - @property - def resp(self): - return {"report": "The list of directories in the path"} - - @property - def id(self): - return "list_directories" - - @property - def desc(self): - return "List directories in a given path" - - def run(self, path): - try: - data = [f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))] - data = {"report": data} - return data - except Exception as e: - return {"report": f"An error occurred while getting directories list: {e}."} class MakeDirectory(BaseTool): @property @@ -80,6 +55,5 @@ def make_dir(newdirpath): DirectoryTools = [ CurrentWorkingDir, - ListDirectories, MakeDirectory ] \ No newline at end of file From 40a54223e4ccd88462d3a533162420e2d1cc9b0d Mon Sep 17 00:00:00 2001 From: FayazRahman Date: Sun, 30 Apr 2023 13:46:22 +0530 Subject: [PATCH 3/5] move to filesystem --- addons/directory_tools.py | 59 ------------------------------------- loopgpt/tools/filesystem.py | 46 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 59 deletions(-) delete mode 100644 addons/directory_tools.py diff --git a/addons/directory_tools.py b/addons/directory_tools.py deleted file mode 100644 index 92a5f05..0000000 --- a/addons/directory_tools.py +++ /dev/null @@ -1,59 +0,0 @@ -from loopgpt.tools import BaseTool -import os - -class CurrentWorkingDir(BaseTool): - @property - def args(self): - return {} - - @property - def resp(self): - return {"report": "The current working directory"} - - @property - def id(self): - return "current_directory" - - @property - def desc(self): - return "The current working directory/folder" - - def run(self): - try: - data = os.getcwd() - data = {"report": data} - return data - except Exception as e: - return {"report": f"An error occurred while getting the current working directory: {e}."} - -class MakeDirectory(BaseTool): - @property - def args(self): - return {"newpath": "path/to/directory"} - - @property - def resp(self): - return {"report": "The path to the directory to be made"} - - @property - def id(self): - return "make_dir" - - @property - def desc(self): - return "Make a directory/folder to the given path" - - def run(self, newpath): - try: - def make_dir(newdirpath): - if not os.path.isdir(newdirpath): - os.makedirs(newdirpath) - make_dir(newpath) - return {"report": f"Directory '{newpath}' was created" } - except Exception as e: - return {"report": f"An error occurred while creating a new directory path: {e}."} - -DirectoryTools = [ - CurrentWorkingDir, - MakeDirectory -] \ No newline at end of file diff --git a/loopgpt/tools/filesystem.py b/loopgpt/tools/filesystem.py index d2eb03e..b39d7cf 100644 --- a/loopgpt/tools/filesystem.py +++ b/loopgpt/tools/filesystem.py @@ -106,6 +106,50 @@ def run(self, *_, **__): return os.listdir() +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 "Path to the current working directory/folder" + + 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, @@ -113,4 +157,6 @@ def run(self, *_, **__): DeleteFile, CheckIfFileExists, ListFiles, + GetCWD, + MakeDirectory, ] From 33e1b6c19fca102ccb62f64890c027cf2690a910 Mon Sep 17 00:00:00 2001 From: FayazRahman Date: Sun, 30 Apr 2023 14:05:02 +0530 Subject: [PATCH 4/5] upd --- loopgpt/tools/filesystem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopgpt/tools/filesystem.py b/loopgpt/tools/filesystem.py index b39d7cf..839166a 100644 --- a/loopgpt/tools/filesystem.py +++ b/loopgpt/tools/filesystem.py @@ -117,7 +117,7 @@ def resp(self): @property def desc(self): - return "Path to the current working directory/folder" + return "Find the current working directory using this command" def run(self): try: From b44370c72649e3c96c084d67633fab650431dba9 Mon Sep 17 00:00:00 2001 From: FayazRahman Date: Sun, 30 Apr 2023 14:08:36 +0530 Subject: [PATCH 5/5] fix --- loopgpt/tools/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/loopgpt/tools/__init__.py b/loopgpt/tools/__init__.py index d7c282f..9ea05f6 100644 --- a/loopgpt/tools/__init__.py +++ b/loopgpt/tools/__init__.py @@ -16,6 +16,8 @@ DeleteFile, CheckIfFileExists, ListFiles, + GetCWD, + MakeDirectory, FileSystemTools, ) from loopgpt.tools.shell import Shell