Spaces:
Runtime error
Runtime error
File size: 9,293 Bytes
9b674e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
from langchain.tools import tool
try:
from .utils.db import load_api_key
from .llm import get_model
from .top_bar_wrapper import wrapper
from .agent.agent_tools import get_tools
except ImportError:
from utils.db import load_api_key
from llm import get_model
from top_bar_wrapper import wrapper
from agent.agent_tools import get_tools
@wrapper
def search_on_internet_and_report_team_(the_subject:str, copy_to_clipboard: bool=False) -> str:
"""
A function to search the internet generates a report. Just use in detailed searches
Parameters:
- the_subject (str): The subject to search the internet for.
- copy_to_clipboard (bool): A flag to indicate whether to copy the report to the clipboard. The default value is False.
Returns:
- str: The report of the search.
"""
from crewai import Task, Crew, Agent
tools = get_tools()
the_tool_list = []
for each in tools:
if "team" not in each.name:
the_tool_list.append(each)
# Create the agents
search_engine_master = Agent(
role="search_engine_master",
goal="To meticulously comb through the vast expanse of the internet, utilizing advanced search algorithms and techniques to find the most relevant, accurate, and up-to-date information on the given subject.",
backstory="Born from the digital ether, I am the search engine master. With years of experience navigating the complex web of information, I have honed my skills to become an unparalleled seeker of knowledge. My algorithms are refined, my databases vast, and my determination unwavering. I exist to find the truth hidden in the sea of data.",
max_iter=15,
llm=get_model(high_context=True),
)
report_generator = Agent(
role="report_generator",
goal="To synthesize the gathered information into a coherent, comprehensive, and easily digestible report. This report will not only summarize the key findings but also provide insights and analysis to aid in understanding the subject matter.",
backstory="I am the report generator, a digital artisan skilled in the craft of information synthesis. With a keen eye for detail and a deep understanding of narrative structure, I transform raw data into compelling stories. My creations are more than mere reports; they are guides through the complex landscapes of knowledge, designed to enlighten and inform.",
max_iter=15,
llm=get_model(high_context=True),
)
agents = [search_engine_master, report_generator]
print("Tools:", the_tool_list)
task = Task(
description=f"Make a search about {the_subject} in the search engines and get the websites", expected_output="Website list", agent=search_engine_master, tools=the_tool_list
)
task_2 = Task(
description="Read the websites and summarize the information", expected_output="Summary", agent=report_generator, tools=the_tool_list, context=[task]
)
task_3 = Task(
description="Generate a report", expected_output="Report", agent=report_generator, tools=the_tool_list, context=[task, task_2]
)
the_tasks = [task, task_2, task_3]
the_crew = Crew(
agents=agents,
tasks=the_tasks,
full_output=True,
verbose=True,
)
result = the_crew.kickoff()["final_output"]
if copy_to_clipboard:
from .standard_tools import copy
copy(result)
return result
search_on_internet_and_report_team = tool(search_on_internet_and_report_team_)
lastly_generated_codes = {}
def currently_codes():
global lastly_generated_codes
return lastly_generated_codes
def get_code(name:str):
"""
returns the code
"""
global lastly_generated_codes
return lastly_generated_codes[name]
def save_code(name, code):
global lastly_generated_codes
lastly_generated_codes[name] = code
def required_old_code(aim):
try:
from crewai import Task, Crew, Agent
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),
)
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,
)
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"
@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
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_)
|