Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,15 +19,20 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
-
|
23 |
-
def
|
24 |
"""
|
25 |
A tool that generates a visual tree structure of the directory contents.
|
26 |
|
27 |
Args:
|
28 |
directory: The path to the directory to inspect.
|
29 |
prefix: Optional argument defaulting to '', used for calling the function recursively.
|
|
|
|
|
30 |
"""
|
|
|
|
|
|
|
31 |
tree_str = ''
|
32 |
contents = os.listdir(directory)
|
33 |
directories = sorted([d for d in contents if os.path.isdir(os.path.join(directory, d))], key=str.lower)
|
@@ -40,7 +45,19 @@ def inspect_directory(directory: str, prefix: str = '') -> str:
|
|
40 |
path = os.path.join(directory, content)
|
41 |
if os.path.isdir(path):
|
42 |
extension = ' ' if content == pointers[0] else '│ '
|
43 |
-
tree_str +=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
return tree_str
|
45 |
|
46 |
@tool
|
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
+
# Only for test purposes as it uses a recursive approach, meaning you'll run out of stack for a large repo.
|
23 |
+
def _tree(directory: str, prefix: str = '', level: int = 0, max_depth: int = 3) -> str:
|
24 |
"""
|
25 |
A tool that generates a visual tree structure of the directory contents.
|
26 |
|
27 |
Args:
|
28 |
directory: The path to the directory to inspect.
|
29 |
prefix: Optional argument defaulting to '', used for calling the function recursively.
|
30 |
+
level: The current level of directory depth.
|
31 |
+
max_depth: The maximum level of directory depth to inspect.
|
32 |
"""
|
33 |
+
if level > max_depth:
|
34 |
+
return ''
|
35 |
+
|
36 |
tree_str = ''
|
37 |
contents = os.listdir(directory)
|
38 |
directories = sorted([d for d in contents if os.path.isdir(os.path.join(directory, d))], key=str.lower)
|
|
|
45 |
path = os.path.join(directory, content)
|
46 |
if os.path.isdir(path):
|
47 |
extension = ' ' if content == pointers[0] else '│ '
|
48 |
+
tree_str += _tree(path, prefix=prefix + extension, level=level + 1, max_depth=max_depths)
|
49 |
+
return tree_str
|
50 |
+
|
51 |
+
@tool
|
52 |
+
def inspect_directory(directory: str, max_depth: int = 3) -> str:
|
53 |
+
"""
|
54 |
+
A tool that generates a visual tree structure of the directory contents.
|
55 |
+
|
56 |
+
Args:
|
57 |
+
directory: The path to the directory to inspect.
|
58 |
+
max_depth: The maximum level of directory depth to inspect.
|
59 |
+
"""
|
60 |
+
tree_str = _tree(directory, max_depth=max_depth)
|
61 |
return tree_str
|
62 |
|
63 |
@tool
|