From 1bcd94ae61c70e983f7ea66d4baa0e0c2672306a Mon Sep 17 00:00:00 2001 From: whimo Date: Fri, 7 Jun 2024 11:00:04 +0400 Subject: [PATCH] Minor improvements for Aider demo --- ...er_example.py => aider_code_generation.py} | 24 +++++++++---------- motleycrew/tools/aider_tool.py | 8 ++++--- 2 files changed, 16 insertions(+), 16 deletions(-) rename examples/{aider_example.py => aider_code_generation.py} (60%) diff --git a/examples/aider_example.py b/examples/aider_code_generation.py similarity index 60% rename from examples/aider_example.py rename to examples/aider_code_generation.py index 4c98991e..e86f6fa9 100644 --- a/examples/aider_example.py +++ b/examples/aider_code_generation.py @@ -34,33 +34,31 @@ def main(): crew = MotleyCrew() - git_dname = r"../../motleycrew-code-generation-example" # aider coder git dir name - tests_file = os.path.join(git_dname, "test_math_functions.py") - fnames = [tests_file] + git_repo_path = r"../../motleycrew-code-generation-example" # cloned repository path + tests_file = os.path.join(git_repo_path, "test_math_functions.py") + target_files = [tests_file] - aider_tool = AiderTool(fnames=fnames, git_dname=git_dname, auto_commits=False) + aider_tool = AiderTool(fnames=target_files, git_dname=git_repo_path, auto_commits=False) shell_tool = ShellTool() developer = CrewAIMotleyAgent( role="Software Engineer", goal="Writing unit tests", - backstory="""You are a leading software engineer working in the field of computer technology""", + backstory="You are a lead software engineer working in a big tech company.", delegation=False, verbose=True, tools=[aider_tool, shell_tool], ) - # Create tasks for your agent create_unit_tests_task = SimpleTask( crew=crew, name="Adding a unit test", - description=f"""Generate unit tests for the module math_functions.py, - using pytest, you can also add checks for possible exceptions and - comments to the tests and using parameterization for test functions. - After go to the directory {git_dname} and run created unit tests for math_functions. - If the tests were executed successfully, return the result of execution, - if not, rewrite the tests and restart them. - """, + description=f"Generate unit tests for the module math_functions.py using pytest. " + f"You should also add test cases for possible exceptions " + f"and write comments to the tests. You should also use test parameterization. " + f"After go to the directory {git_repo_path} and run created unit tests. " + f"If the tests were executed successfully, return the result of execution, " + f"if not, rewrite the tests and rerun them until they are working.", agent=developer, ) diff --git a/motleycrew/tools/aider_tool.py b/motleycrew/tools/aider_tool.py index 54aac631..3c6cfbad 100644 --- a/motleycrew/tools/aider_tool.py +++ b/motleycrew/tools/aider_tool.py @@ -4,7 +4,8 @@ from aider.coders import Coder from aider.models import Model except ImportError: - ensure_module_is_installed("aider-chat", "pip install aider-chat") + Coder = None + Model = None from langchain.tools import Tool from langchain_core.pydantic_v1 import BaseModel, Field @@ -16,12 +17,13 @@ class AiderTool(MotleyTool): def __init__(self, model: str = None, **kwargs): - """ Tool for generating program code + """Tool for code generation using Aider. Args: model (str): model name **kwargs: """ + ensure_module_is_installed("aider", "pip install aider-chat") model = model or Defaults.DEFAULT_LLM_NAME llm_model = Model(model=model) @@ -42,7 +44,7 @@ class AiderToolInput(BaseModel): def create_aider_tool(coder: Coder): - """ Create langchain tool from aider coder + """Create langchain tool from Aider coder.run() method Returns: Tool: