From e433d618ab1d2c4f0d90b8abbf36bf8773e126db Mon Sep 17 00:00:00 2001 From: Owen Colegrove Date: Sun, 23 Apr 2023 21:54:49 -0400 Subject: [PATCH 1/2] cleanup residuals --- .../tests/sample_modules/test_module_2.py | 12 +-- .../codebase_oracle_tool_manager.py | 11 +++ .../documentation_gpt_tool_manager.py | 6 +- .../python_indexer_tool_manager.py | 18 ++-- .../python_writer_tool_manager.py | 89 ++++++++----------- 5 files changed, 66 insertions(+), 70 deletions(-) diff --git a/automata/tools/python_tools/tests/sample_modules/test_module_2.py b/automata/tools/python_tools/tests/sample_modules/test_module_2.py index d8c78d2c..69247537 100644 --- a/automata/tools/python_tools/tests/sample_modules/test_module_2.py +++ b/automata/tools/python_tools/tests/sample_modules/test_module_2.py @@ -1,18 +1,18 @@ -"""HwBMAPYpHSeqtzvSXLHp""" +"""dYbSBeRSJGIepRZrLiPa""" import random -class DcXzO: - """ioeybfBgufVInSEBWpme""" +class xsYsy: + """DVEDtjRAnKBSMNBlHyti""" def __init__(self): pass def method(self): - """NLMpxnCpqZcihwdjaRKc""" + """BnlPUPVEYFVGViiDLyPs""" pass -def vsWJv(): - """xIhewPiiDbHfgARvEaLM""" +def WMSqR(): + """JlbXCnZRwxynSmyyuJyn""" pass diff --git a/automata/tools/tool_management/codebase_oracle_tool_manager.py b/automata/tools/tool_management/codebase_oracle_tool_manager.py index f5e7823f..59e8432a 100644 --- a/automata/tools/tool_management/codebase_oracle_tool_manager.py +++ b/automata/tools/tool_management/codebase_oracle_tool_manager.py @@ -13,6 +13,15 @@ def __init__(self, **kwargs): ) def build_tools(self) -> List[Tool]: + """ + Initializes a CodebaseOracleToolManager object with the given inputs. + + Args: + - codebase_oracle (CodebaseOracle): A CodebaseOracle object which facilitates code searches. + + Returns: + - None + """ tools = [ Tool( name="codebase-oracle-agent", @@ -25,8 +34,10 @@ def build_tools(self) -> List[Tool]: return tools def build_tools_with_automata(self) -> List[Tool]: + """Not implemented.""" raise NotImplementedError def _run_codebase_oracle_agent(self, query: str) -> str: + """Lookup the documentation for the given input text.""" result = run_retrieval_chain_with_sources_format(self.codebase_oracle.get_chain(), query) return result diff --git a/automata/tools/tool_management/documentation_gpt_tool_manager.py b/automata/tools/tool_management/documentation_gpt_tool_manager.py index f51bc1bb..02d7dc44 100644 --- a/automata/tools/tool_management/documentation_gpt_tool_manager.py +++ b/automata/tools/tool_management/documentation_gpt_tool_manager.py @@ -7,9 +7,11 @@ class DocumentationGPTToolManager(BaseToolManager): def __init__(self, **kwargs): + """Initializes a DocumentationGPTToolManager object with the given inputs.""" self.documentation_gpt: DocumentationGPT = kwargs.get("documentation_gpt") def build_tools(self) -> List[Tool]: + """Initializes a DocumentationGPTToolManager object with the given inputs.""" tools = [ Tool( name="doc-gpt-lookup", @@ -21,8 +23,10 @@ def build_tools(self) -> List[Tool]: return tools def build_tools_with_automata(self) -> List[Tool]: - return [] + """Not implemented.""" + raise NotImplementedError def _documentation_gpt_lookup(self, input_text): + """Lookup the documentation for the given input text.""" result = self.documentation_gpt.run(input_text) return result diff --git a/automata/tools/tool_management/python_indexer_tool_manager.py b/automata/tools/tool_management/python_indexer_tool_manager.py index 3d45b102..373385be 100644 --- a/automata/tools/tool_management/python_indexer_tool_manager.py +++ b/automata/tools/tool_management/python_indexer_tool_manager.py @@ -55,15 +55,7 @@ def __init__(self, **kwargs): self.stream = kwargs.get("stream") or True def build_tools(self) -> List[Tool]: - """ - Builds a list of Tool objects for interacting with PythonIndexer. - - Args: - - None - - Returns: - - tools (List[Tool]): A list of Tool objects representing PythonIndexer commands. - """ + """Builds a list of Tool objects for interacting with PythonIndexer.""" tools = [ Tool( name="python-indexer-retrieve-code", @@ -96,6 +88,7 @@ def build_tools(self) -> List[Tool]: return tools def build_tools_with_automata(self) -> List[Tool]: + """Builds a list of Automata powered Tool objects for interacting with PythonWriter.""" tools = [ Tool( name="automata-indexer-retrieve-code", @@ -106,6 +99,7 @@ def build_tools_with_automata(self) -> List[Tool]: return tools def _run_indexer_retrieve_code(self, input_str: str) -> str: + """PythonIndexer retrieves the code of the python package, module, standalone function, class, or method at the given python path, without docstrings.""" try: module_path, object_path = self.parse_input_str(input_str) result = self.indexer.retrieve_code(module_path, object_path) @@ -114,6 +108,7 @@ def _run_indexer_retrieve_code(self, input_str: str) -> str: return "Failed to retrieve code with error - " + str(e) def _run_indexer_retrieve_docstring(self, input_str: str) -> str: + """PythonIndexer retrieves the docstring of the python package, module, standalone function, class, or method at the given python path, without docstrings.""" try: module_path, object_path = self.parse_input_str(input_str) result = self.indexer.retrieve_docstring(module_path, object_path) @@ -122,6 +117,7 @@ def _run_indexer_retrieve_docstring(self, input_str: str) -> str: return "Failed to retrieve docstring with error - " + str(e) def _run_indexer_retrieve_raw_code(self, input_str: str) -> str: + """PythonIndexer retrieves the raw code of the python package, module, standalone function, class, or method at the given python path, with docstrings.""" try: module_path, object_path = self.parse_input_str(input_str) result = self.indexer.retrieve_raw_code(module_path, object_path) @@ -130,12 +126,11 @@ def _run_indexer_retrieve_raw_code(self, input_str: str) -> str: return "Failed to retrieve raw code with error - " + str(e) def _run_automata_indexer_retrieve_code(self, path_str: str) -> str: + """Automata retrieves the code of the python package, module, standalone function, class, or method at the given python path, without docstrings.""" from automata.core import load_llm_toolkits from automata.core.agents.automata_agent import AutomataAgent - """Automata retrieves the code of the python package, module, standalone function, class, or method at the given python path, without docstrings.""" try: - print("Running _run_automata_indexer_retrieve_code with path_str - ", path_str) initial_payload = {"overview": self.indexer.get_overview()} instructions = f"Retrieve the code for {path_str}" agent = AutomataAgent( @@ -156,6 +151,7 @@ def _run_automata_indexer_retrieve_code(self, path_str: str) -> str: @staticmethod def parse_input_str(input_str: str) -> Tuple[str, Optional[str]]: + """Parses the input string into a module path and an optional object path.""" split_input = input_str.split(",") module_path = split_input[0].strip() if len(split_input) == 1: diff --git a/automata/tools/tool_management/python_writer_tool_manager.py b/automata/tools/tool_management/python_writer_tool_manager.py index 603e879e..3f2dd8c3 100644 --- a/automata/tools/tool_management/python_writer_tool_manager.py +++ b/automata/tools/tool_management/python_writer_tool_manager.py @@ -8,7 +8,6 @@ - writer (PythonWriter): A PythonWriter object for manipulating local pythonf iles. Example - - Build a list of Tool objects for interacting with PythonWriter: python_indexer = PythonIndexer(root_py_path()) python_writer = PythonWriter(python_indexer) python_writer_tool_manager = PythonWriterToolManager(python_writer) @@ -53,7 +52,41 @@ def __init__( self.stream = kwargs.get("stream") or True self.temperature = kwargs.get("temperature") or 0.7 - def writer_update_module(self, input_str: str) -> str: + def build_tools(self) -> List[Tool]: + """Builds a list of Tool object for interacting with PythonWriter.""" + tools = [ + Tool( + name="python-writer-update-module", + func=lambda path_comma_code_str: self._writer_update_module(path_comma_code_str), + description=f"Modifies the python code of a function, class, method, or module after receiving" + f" an input module path, source code, and optional class name. If the specified object or dependencies do not exist," + f" then they are created automatically. If the object already exists," + f" then the existing code is modified." + f" For example -" + f' to implement a method "my_method" of "MyClass" in the module "my_file.py" which exists in "my_folder",' + f" the correct function call is" + f' {{"tool": "python-writer-update-module",' + f' "input": "my_folder.my_file,MyClass,def my_function() -> None:\n """My Function"""\n print("hello world")"}}.' + f" If new import statements are necessary, then introduce them to the module separately. Do not forget to wrap your input in double quotes.", + return_direct=True, + ), + ] + return tools + + def build_tools_with_automata(self) -> List[Tool]: + """Builds a list of Automata powered tool objects for interacting with PythonWriter.""" + tools = [ + Tool( + name="automata-writer-modify-module", + func=lambda path_comma_code_str: self._automata_update_module(path_comma_code_str), + description=f"Modifies the python code of a function, class, method, or module after receiving" + f" an input module path, source code, and optional class name. The actual work is carried out by an autonomous agent called Automata.", + ), + ] + return tools + + def _writer_update_module(self, input_str: str) -> str: + """Writes the given code to the given module path and class name.""" module_path = input_str.split(",")[0] class_name = input_str.split(",")[1] code = ",".join(input_str.split(",")[2:]).strip() @@ -69,7 +102,8 @@ def writer_update_module(self, input_str: str) -> str: except Exception as e: return "Failed to update the module with error - " + str(e) - def automata_update_module(self, input_str: str) -> str: + def _automata_update_module(self, input_str: str) -> str: + """Creates an AutomataAgent to write the given task.""" from automata.core import load_llm_toolkits from automata.core.agents.automata_agent import AutomataAgent @@ -92,52 +126,3 @@ def automata_update_module(self, input_str: str) -> str: return "Success" except Exception as e: return "Failed to update the module with error - " + str(e) - - def build_tools(self) -> List[Tool]: - """ - Builds a list of Tool object for interacting with PythonWriter. - - Args: - - None - - Returns: - - tools (List[Tool]): A list of Tool objects representing PythonWriter commands. - """ - tools = [ - Tool( - name="python-writer-update-module", - func=lambda path_comma_code_str: self.writer_update_module(path_comma_code_str), - description=f"Modifies the python code of a function, class, method, or module after receiving" - f" an input module path, source code, and optional class name. If the specified object or dependencies do not exist," - f" then they are created automatically. If the object already exists," - f" then the existing code is modified." - f" For example -" - f' to implement a method "my_method" of "MyClass" in the module "my_file.py" which exists in "my_folder",' - f" the correct function call is" - f' {{"tool": "python-writer-update-module",' - f' "input": "my_folder.my_file,MyClass,def my_function() -> None:\n """My Function"""\n print("hello world")"}}.' - f" If new import statements are necessary, then introduce them to the module separately. Do not forget to wrap your input in double quotes.", - return_direct=True, - ), - ] - return tools - - def build_tools_with_automata(self) -> List[Tool]: - """ - Builds a list of Tool object for interacting with PythonWriter. - - Args: - - None - - Returns: - - tools (List[Tool]): A list of Tool objects representing PythonWriter commands. - """ - tools = [ - Tool( - name="automata-writer-modify-module", - func=lambda path_comma_code_str: self.automata_update_module(path_comma_code_str), - description=f"Modifies the python code of a function, class, method, or module after receiving" - f" an input module path, source code, and optional class name. The actual work is carried out by an autonomous agent called Automata.", - ), - ] - return tools From 160383e89a827d91d38d4b96de9310e14ad0c21a Mon Sep 17 00:00:00 2001 From: Owen Colegrove Date: Sun, 23 Apr 2023 21:56:07 -0400 Subject: [PATCH 2/2] remove cruft --- .gitignore | 1 + .../tests/sample_modules/test_module_2.py | 18 ------------------ 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 automata/tools/python_tools/tests/sample_modules/test_module_2.py diff --git a/.gitignore b/.gitignore index 90853924..4fcf2e3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +**/sample_modules/** interactions.sqlite3 /.idea/ .env diff --git a/automata/tools/python_tools/tests/sample_modules/test_module_2.py b/automata/tools/python_tools/tests/sample_modules/test_module_2.py deleted file mode 100644 index 69247537..00000000 --- a/automata/tools/python_tools/tests/sample_modules/test_module_2.py +++ /dev/null @@ -1,18 +0,0 @@ -"""dYbSBeRSJGIepRZrLiPa""" -import random - - -class xsYsy: - """DVEDtjRAnKBSMNBlHyti""" - - def __init__(self): - pass - - def method(self): - """BnlPUPVEYFVGViiDLyPs""" - pass - - -def WMSqR(): - """JlbXCnZRwxynSmyyuJyn""" - pass