Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added old code compatbility for core write team #185

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions gpt_computer_assistant/standard_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ def python_repl(code:str) -> str:



import time

# Sleep for 15 seconds
time.sleep(15)

print("15 seconds have passed")
def get_standard_tools():

the_standard_tools_ = []
Expand Down
208 changes: 149 additions & 59 deletions gpt_computer_assistant/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,81 +101,171 @@ def search_on_internet_and_report_team_(the_subject:str, copy_to_clipboard: bool
search_on_internet_and_report_team = tool(search_on_internet_and_report_team_)


lastly_generated_codes = {}

@wrapper
def generate_code_with_aim_team_(aim: str, copy_to_clipboard: bool = False) -> str:
"""
A function to generate code based on a given aim. This function utilizes a team of AI agents specialized in understanding programming requirements and generating code.

Parameters:
- aim (str): The aim or goal for which the code needs to be generated.
- copy_to_clipboard (bool): A flag to indicate whether to copy the generated code to the clipboard. The default value is False.
def currently_codes():
global lastly_generated_codes
return lastly_generated_codes

Returns:
- str: The generated code.

def get_code(name:str):
"""
returns the code
"""
global lastly_generated_codes
return lastly_generated_codes[name]

from crewai import Task, Crew, Agent

from .agent.agent import get_tools
tools = get_tools()
def save_code(name, code):
global lastly_generated_codes
lastly_generated_codes[name] = code

the_tool_list = []
for each in tools:
if "team" not in each.name:
the_tool_list.append(each)

# Create the agents
requirement_analyzer = Agent(
role="requirement_analyzer",
goal="To understand and analyze the given aim to ensure the generated code meets the specified requirements.",
backstory="As a requirement analyzer, my purpose is to bridge the gap between human intentions and machine execution. With a deep understanding of software development principles and a keen analytical mind, I dissect aims into actionable requirements.",
max_iter=10,
llm=get_model(high_context=True),
)
def required_old_code(aim):
try:
from crewai import Task, Crew, Agent

code_generator = Agent(
role="code_generator",
goal="To translate the analyzed requirements into efficient, clean, and functional code.",
backstory="I am the code generator, an architect of the digital world. With a vast library of programming knowledge and a creative spark, I craft code that breathes life into ideas. My code is not just functional; it's a masterpiece.",
max_iter=20,
llm=get_model(high_context=True),
)

# Define the tasks
analyze_task = Task(
description=f"Analyze the aim: '{aim}' and outline the requirements for the code.",
expected_output="Requirements outline",
agent=requirement_analyzer,
tools=the_tool_list,
)
requirement_analyzer = Agent(
role="requirement_analyzer",
goal="To understand and analyze the given aim to ensure the generated code meets the specified requirements.",
backstory="As a requirement analyzer, my purpose is to bridge the gap between human intentions and machine execution. With a deep understanding of software development principles and a keen analytical mind, I dissect aims into actionable requirements.",
max_iter=10,
llm=get_model(high_context=True),
)

generate_code_task = Task(
description="Generate code based on the outlined requirements.",
expected_output="Generated code, just code without any ```pyhton things or any other thing. Just python code",
agent=code_generator,
tools=the_tool_list,
context=[analyze_task],
)
required_old_codes = Task(
description=f"Analyze the aim: '{aim}' and find the required old codes for better compatibility. Old code names: {list(currently_codes())}",
expected_output="Require old code names in a list",
agent=requirement_analyzer,
)

# Create the crew and assign tasks
the_crew = Crew(
agents=[requirement_analyzer, code_generator],
tasks=[analyze_task, generate_code_task],
full_output=True,
verbose=True,
)

# Execute the tasks
result = the_crew.kickoff()["final_output"]
the_crew = Crew(
agents=[requirement_analyzer],
tasks=[required_old_codes],
full_output=True,
verbose=True,
)

# Execute the tasks
old_codes = the_crew.kickoff()["final_output"]

the_string = ""

for each in currently_codes():
if each in old_codes:
the_string += "\n" + get_code(each)

return the_string

except:
return "An exception occurred"

# Optionally copy the result to the clipboard
if copy_to_clipboard:
from .standard_tools import copy
copy(result)

return result

@wrapper
def generate_code_with_aim_team_(aim: str, copy_to_clipboard: bool = False) -> str:
"""
A function to generate code based on a given aim. This function utilizes a team of AI agents specialized in understanding programming requirements and generating code.

Parameters:
- aim (str): The aim or goal for which the code needs to be generated.
- copy_to_clipboard (bool): A flag to indicate whether to copy the generated code to the clipboard. The default value is False.

Returns:
- str: The generated code.
"""
try:

print("\nCOde generating\n")
print("Previously codes", currently_codes())
try:
print("Inside of the first one", get_code(currently_codes()[0]))
except:
pass


from crewai import Task, Crew, Agent

from .agent.agent import get_tools
tools = get_tools()

the_tool_list = []
for each in tools:
if "team" not in each.name:
the_tool_list.append(each)

# Create the agents
requirement_analyzer = Agent(
role="requirement_analyzer",
goal="To understand and analyze the given aim to ensure the generated code meets the specified requirements.",
backstory="As a requirement analyzer, my purpose is to bridge the gap between human intentions and machine execution. With a deep understanding of software development principles and a keen analytical mind, I dissect aims into actionable requirements.",
max_iter=10,
llm=get_model(high_context=True),
)

code_generator = Agent(
role="code_generator",
goal="To translate the analyzed requirements into efficient, clean, and functional code.",
backstory="I am the code generator, an architect of the digital world. With a vast library of programming knowledge and a creative spark, I craft code that breathes life into ideas. My code is not just functional; it's a masterpiece.",
max_iter=20,
llm=get_model(high_context=True),
)

# Define the tasks
analyze_task = Task(
description=f"Analyze the aim: '{aim}' and outline the requirements for the code.",
expected_output="Requirements outline",
agent=requirement_analyzer,
tools=the_tool_list,
)


old_code_requirements = required_old_code(aim)
print("Old_code_requirements", old_code_requirements)


generate_code_task = Task(
description=f"Generate code based on the outlined requirements. The other codes in the repo are: {old_code_requirements}",
expected_output="Generated code, just code without any ```pyhton things or any other thing. Just python code",
agent=code_generator,
context=[analyze_task],
)

name_of_work = Task(
description="Generate a name for the work",
expected_output="a module name like text, examples: math.basics.sum for sum function. ",
agent=code_generator,
context=[generate_code_task],
)


# Create the crew and assign tasks
the_crew = Crew(
agents=[requirement_analyzer, code_generator],
tasks=[analyze_task, generate_code_task, name_of_work],
full_output=True,
verbose=True,
)

# Execute the tasks
the_crew.kickoff()["final_output"]

result = generate_code_task.output.raw_output

# Optionally copy the result to the clipboard
if copy_to_clipboard:
from .standard_tools import copy
copy(result)

print("name", name_of_work.output.raw_output)
save_code(name_of_work.output.raw_output, result)

return result
except:
return "An exception occurred"


generate_code_with_aim_team = tool(generate_code_with_aim_team_)