Skip to content

Commit c3abb3b

Browse files
authored
Merge pull request #22 from iskandarreza/directory_custom_tools
Directory custom tools - CurrentWorkingDir, MakeDirectory
2 parents faedc19 + b44370c commit c3abb3b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

loopgpt/tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
DeleteFile,
1818
CheckIfFileExists,
1919
ListFiles,
20+
GetCWD,
21+
MakeDirectory,
2022
FileSystemTools,
2123
)
2224
from loopgpt.tools.shell import Shell

loopgpt/tools/filesystem.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,57 @@ def run(self, path, recursive, show_hidden=False, exclude_dirs=False):
126126
return {"result": entries_list}
127127

128128

129+
class GetCWD(BaseTool):
130+
@property
131+
def args(self):
132+
return {}
133+
134+
@property
135+
def resp(self):
136+
return {"path": "Path to the current working directory"}
137+
138+
@property
139+
def desc(self):
140+
return "Find the current working directory using this command"
141+
142+
def run(self):
143+
try:
144+
cwd = os.getcwd()
145+
return {"path": cwd}
146+
except Exception as e:
147+
return (
148+
f"An error occurred while getting the current working directory: {e}."
149+
)
150+
151+
152+
class MakeDirectory(BaseTool):
153+
@property
154+
def args(self):
155+
return {"path": "Path of the directory to be made"}
156+
157+
@property
158+
def resp(self):
159+
return {"success": "True if the directory was created, False otherwise."}
160+
161+
@property
162+
def desc(self):
163+
return "Make a new directory at the given path"
164+
165+
def run(self, path):
166+
try:
167+
os.makedirs(path)
168+
return {"success": True}
169+
except Exception as e:
170+
return f"An error occurred while creating a new directory path: {e}."
171+
172+
129173
FileSystemTools = [
130174
WriteToFile,
131175
ReadFromFile,
132176
AppendToFile,
133177
DeleteFile,
134178
CheckIfFileExists,
135179
ListFiles,
180+
GetCWD,
181+
MakeDirectory,
136182
]

0 commit comments

Comments
 (0)