Skip to content

Commit

Permalink
Minor improvements for Aider demo
Browse files Browse the repository at this point in the history
  • Loading branch information
whimo committed Jun 7, 2024
1 parent 911f045 commit 1bcd94a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 11 additions & 13 deletions examples/aider_example.py → examples/aider_code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
8 changes: 5 additions & 3 deletions motleycrew/tools/aider_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 1bcd94a

Please sign in to comment.