From 1e4732807931f815feb3f6dfab22b5f7c4d0ce15 Mon Sep 17 00:00:00 2001 From: slavakurilyak Date: Tue, 4 Apr 2023 20:32:15 -0500 Subject: [PATCH] Add search files command --- scripts/commands.py | 4 +++- scripts/data/prompt.txt | 11 ++++++----- scripts/file_operations.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/commands.py b/scripts/commands.py index c1d5db9d3..a6e8f7451 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 a93e783eb..75d9312a4 100644 --- a/scripts/data/prompt.txt +++ b/scripts/data/prompt.txt @@ -19,11 +19,12 @@ COMMANDS: 11. Read file: "read_file", args: "file": "" 12. Append to file: "append_to_file", args: "file": "", "text": "" 13. Delete file: "delete_file", args: "file": "" -14. Evaluate Code: "evaluate_code", args: "code": "" -15. Get Improved Code: "improve_code", args: "suggestions": "", "code": "" -16. Write Tests: "write_tests", args: "code": "", "focus": "" -17. Execute Python File: "execute_python_file", args: "file": "" -18. Task Complete (Shutdown): "task_complete", args: "reason": "" +14. Search Files: "search_files", args: "directory": "" +15. Evaluate Code: "evaluate_code", args: "code": "" +16. Get Improved Code: "improve_code", args: "suggestions": "", "code": "" +17. Write Tests: "write_tests", args: "code": "", "focus": "" +18. Execute Python File: "execute_python_file", args: "file": "" +19. Task Complete (Shutdown): "task_complete", args: "reason": "" RESOURCES: diff --git a/scripts/file_operations.py b/scripts/file_operations.py index 81ad47157..f3cd3a458 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