Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Add search files command

slavakurilyak1e4732807931
diff --git a/scripts/commands.py b/scripts/commands.py
index c1d5db9d30..a6e8f74513 100644
--- a/scripts/commands.py
+++ b/scripts/commands.py
@@ -6,7 +6,7 @@ import agent_manager as agents
import speak
from config import Config
import ai_functions as ai
-from file_operations import read_file, write_to_file, append_to_file, delete_file
+from file_operations import read_file, write_to_file, append_to_file, delete_file, search_files
from execute_code import execute_python_file
from json_parser import fix_and_parse_json
from duckduckgo_search import ddg
@@ -90,6 +90,8 @@ def execute_command(command_name, arguments):
return append_to_file(arguments["file"], arguments["text"])
elif command_name == "delete_file":
return delete_file(arguments["file"])
+ elif command_name == "search_files":
+ return search_files(arguments["directory"])
elif command_name == "browse_website":
return browse_website(arguments["url"], arguments["question"])
# TODO: Change these to take in a file rather than pasted code, if
diff --git a/scripts/data/prompt.txt b/scripts/data/prompt.txt
index a93e783eb3..75d9312a45 100644
--- a/scripts/data/prompt.txt
+++ b/scripts/data/prompt.txt
@@ -19,11 +19,12 @@ COMMANDS:
11. Read file: "read_file", args: "file": "<file>"
12. Append to file: "append_to_file", args: "file": "<file>", "text": "<text>"
13. Delete file: "delete_file", args: "file": "<file>"
-14. Evaluate Code: "evaluate_code", args: "code": "<full _code_string>"
-15. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>"
-16. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>"
-17. Execute Python File: "execute_python_file", args: "file": "<file>"
-18. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"
+14. Search Files: "search_files", args: "directory": "<directory>"
+15. Evaluate Code: "evaluate_code", args: "code": "<full _code_string>"
+16. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>"
+17. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>"
+18. Execute Python File: "execute_python_file", args: "file": "<file>"
+19. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"
RESOURCES:
diff --git a/scripts/file_operations.py b/scripts/file_operations.py
index 81ad471577..f3cd3a458b 100644
--- a/scripts/file_operations.py
+++ b/scripts/file_operations.py
@@ -58,3 +58,16 @@ def delete_file(filename):
return "File deleted successfully."
except Exception as e:
return "Error: " + str(e)
+
+def search_files(directory):
+ found_files = []
+ search_directory = safe_join(working_directory, directory)
+
+ for root, _, files in os.walk(search_directory):
+ for file in files:
+ if file.startswith('.'):
+ continue
+ relative_path = os.path.relpath(os.path.join(root, file), working_directory)
+ found_files.append(relative_path)
+
+ return found_files
\ No newline at end of file