From 1f3ea519625283758bc7a3029f914e6b05ab45ef Mon Sep 17 00:00:00 2001 From: Shruti Patel Date: Wed, 8 Nov 2023 02:45:34 -0500 Subject: [PATCH] Fix --- .gitignore | 2 +- src/repo_gpt/cli.py | 90 +++++++++++------------ src/repo_gpt/code_manager/code_manager.py | 2 +- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index e5db574..ce69a5a 100644 --- a/.gitignore +++ b/.gitignore @@ -232,4 +232,4 @@ fabric.properties # Can't be having folks committing the crime of sharing their creds .env -expt/* +expt diff --git a/src/repo_gpt/cli.py b/src/repo_gpt/cli.py index 45ecdd4..69f6028 100755 --- a/src/repo_gpt/cli.py +++ b/src/repo_gpt/cli.py @@ -106,16 +106,13 @@ def print_help(): parser_help = subparsers.add_parser("help", help="Show this help message") parser_help.set_defaults(func=print_help) - args = parser.parse_args() + args, _ = parser.parse_known_args() # Services openai_service = OpenAIService() - search_service = ( - SearchService(openai_service, args.pickle_path) - if args.command not in ["setup", "explain"] - else None - ) + search_service = SearchService(openai_service, args.pickle_path) + if int(args.verbose) >= 1: configure_logging(VERBOSE_INFO) @@ -125,60 +122,62 @@ def print_help(): manager = CodeManager(pickle_path, code_root_path) manager.setup() elif args.command == "search": - update_code_embedding_file(args.pickle_path) + update_code_embedding_file( + search_service, args.code_root_path, args.pickle_path + ) + _, additional_args = parser_search.parse_known_args() # search_service.simple_search(args.query) # simple search - search_service.semantic_search(args.query) # semantic search + search_service.semantic_search(additional_args[0]) # semantic search elif args.command == "query": - update_code_embedding_file(args.pickle_path) - repo_qna = RepoQnA(args.question, args.code_root_path) + update_code_embedding_file( + search_service, args.code_root_path, args.pickle_path + ) + _, additional_args = parser_query.parse_known_args() + repo_qna = RepoQnA(additional_args[0], args.code_root_path, args.pickle_path) repo_qna.initiate_chat() elif args.command == "explain": - update_code_embedding_file(args.pickle_path) - search_service.explain(args.question) + update_code_embedding_file( + search_service, args.code_root_path, args.pickle_path + ) + _, additional_args = explain_code.parse_known_args() + search_service.explain(additional_args[0]) elif args.command == "analyze": # TODO change to explain function - update_code_embedding_file(args.pickle_path) - search_service.analyze_file(args.file_path) + update_code_embedding_file( + search_service, args.code_root_path, args.pickle_path + ) + _, additional_args = analyze_file.parse_known_args() + search_service.analyze_file(additional_args[0]) elif args.command == "explain": search_service = SearchService(openai_service, language=args.language) - return search_service.explain(args.code) + _, additional_args = explain_code.parse_known_args() + return search_service.explain(additional_args[0]) elif args.command == "add-test": - code_manager = CodeManager(args.pickle_path) - # Look for the function name in the embedding file - add_tests( - search_service, - code_manager, - args.function_name, - args.test_save_file_path, - args.testing_package, + update_code_embedding_file( + search_service, args.code_root_path, args.pickle_path ) + code_manager = CodeManager(Path(args.pickle_path), Path(args.code_root_path)) + # Look for the function name in the embedding file + _, additional_args = add_test.parse_known_args() + # print(additional_args) + + print("Adding tests is temporarily disabled due to a bug in the cli parser.") + # add_tests( + # search_service, + # code_manager, + # args.function_name, + # args.test_save_file_path, + # args.testing_package, + # ) else: parser.print_help() def update_code_embedding_file( - search_service, code_embedding_file_path, function_name=None + search_service, root_file_path: str, code_embedding_file_path: str ) -> Union[None, str]: - manager = CodeManager(code_embedding_file_path) - if function_name: - function_to_test_df, class_to_test_df = search_service.find_function_match( - function_name - ) - - if function_to_test_df.empty: - print(f"Function {function_name} not found.") - return - - checksum_filepath_dict = { - function_to_test_df.iloc[0]["file_checksum"]: function_to_test_df.iloc[0][ - "filepath" - ] - } - manager.parse_code_and_save_embeddings(checksum_filepath_dict) - - return function_to_test_df.iloc[0]["code"] - else: - manager.setup() - search_service.refresh() + manager = CodeManager(Path(code_embedding_file_path), Path(root_file_path)) + manager.setup() + search_service.refresh_df() def add_tests( @@ -196,6 +195,7 @@ def add_tests( ) return + # TODO: check this. it seems wrong code = update_code_embedding_file(search_service, code_manager, function_name) # Save gpt history diff --git a/src/repo_gpt/code_manager/code_manager.py b/src/repo_gpt/code_manager/code_manager.py index a3e3b70..27f9c7d 100644 --- a/src/repo_gpt/code_manager/code_manager.py +++ b/src/repo_gpt/code_manager/code_manager.py @@ -18,7 +18,7 @@ class CodeManager: def __init__( self, output_filepath: Path, - root_directory: Path = None, + root_directory: Path, openai_service: OpenAIService = None, ): self.root_directory = root_directory