Skip to content

Commit

Permalink
Merge pull request emrgnt-cmplxty#52 from maks-ivanov/feature/cleanup…
Browse files Browse the repository at this point in the history
…-automata

cleanup residuals
  • Loading branch information
emrgnt-cmplxty authored Apr 24, 2023
2 parents 3e3d921 + 160383e commit 145858d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/sample_modules/**
interactions.sqlite3
/.idea/
.env
Expand Down
18 changes: 0 additions & 18 deletions automata/tools/python_tools/tests/sample_modules/test_module_2.py

This file was deleted.

11 changes: 11 additions & 0 deletions automata/tools/tool_management/codebase_oracle_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
18 changes: 7 additions & 11 deletions automata/tools/tool_management/python_indexer_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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:
Expand Down
89 changes: 37 additions & 52 deletions automata/tools/tool_management/python_writer_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand All @@ -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

0 comments on commit 145858d

Please sign in to comment.