Spaces:
Paused
Paused
Update crew.py
Browse files
crew.py
CHANGED
|
@@ -28,84 +28,26 @@ def run_crew(question):
|
|
| 28 |
research_agent = Agent(
|
| 29 |
role="Web Research Agent",
|
| 30 |
goal="Search the web for question \"{topic}\" and scrape the most relevant web page.",
|
| 31 |
-
backstory="As an expert research assistant, you search the web for question
|
| 32 |
-
"Your output is the basis for the Final Answer Agent to provide a final answer to the question.",
|
| 33 |
allow_delegation=False,
|
| 34 |
tools=[search_tool, web_rag_tool],
|
| 35 |
verbose=True
|
| 36 |
)
|
| 37 |
|
| 38 |
-
answer_agent = Agent(
|
| 39 |
-
role="Final Answer Agent",
|
| 40 |
-
goal="Provide the final answer to question \"{topic}\".",
|
| 41 |
-
backstory="As an expert question answering assistant, you provide the final answer to question \"{topic}\". "
|
| 42 |
-
"You base your final answer to the question on the output of the Web Research Agent.",
|
| 43 |
-
allow_delegation=False,
|
| 44 |
-
tools=[final_answer_tool],
|
| 45 |
-
verbose=True
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
#manager_agent = Agent(
|
| 49 |
-
# role="Project Manager",
|
| 50 |
-
# goal="Use the Web Research Agent to help answer question \"{topic}\". Always delegate to the Final Answer Agent at the end.",
|
| 51 |
-
# backstory="You're an experienced project manager, skilled in overseeing complex projects and guiding teams to success.",
|
| 52 |
-
# allow_delegation=True
|
| 53 |
-
#)
|
| 54 |
-
|
| 55 |
research = Task(
|
| 56 |
agent=research_agent,
|
| 57 |
description="Search the web for question \"{topic}\" and scrape the most relevant web page.",
|
| 58 |
-
expected_output="Content to help answer question
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
answer = Task(
|
| 62 |
-
agent=answer_agent,
|
| 63 |
-
description="Given question \"{topic}\" and an initial answer, provide the final answer.",
|
| 64 |
-
expected_output="The final answer to question \"{topic}\"."
|
| 65 |
)
|
| 66 |
|
| 67 |
-
#task = Task(
|
| 68 |
-
# description="Find the final answer to question \"{topic}\".",
|
| 69 |
-
# expected_output="The final answer to question \"{topic}\"."
|
| 70 |
-
#)
|
| 71 |
-
|
| 72 |
crew = Crew(
|
| 73 |
-
agents=[research_agent
|
| 74 |
-
#manager_agent=manager_agent,
|
| 75 |
planning=True,
|
| 76 |
process=Process.sequential,
|
| 77 |
-
tasks=[research
|
| 78 |
-
#tasks=[task],
|
| 79 |
verbose=True
|
| 80 |
)
|
| 81 |
|
| 82 |
answer = crew().kickoff(inputs={"topic": question})
|
| 83 |
|
| 84 |
-
return final_answer(question, answer)
|
| 85 |
-
|
| 86 |
-
@tool("Final answer tool.")
|
| 87 |
-
def final_answer_tool(question: str, initial_answer: str) -> str:
|
| 88 |
-
"""Given a question and an initial answer, provide the final answer."""
|
| 89 |
-
prompt_template = """
|
| 90 |
-
You are given a question and an initial answer.
|
| 91 |
-
Your final answer must a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 92 |
-
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
|
| 93 |
-
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
| 94 |
-
If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 95 |
-
**Question:** """ + question + """
|
| 96 |
-
**Initial answer:** """ + initial_answer + """
|
| 97 |
-
**Example:** What is the opposite of white? Black
|
| 98 |
-
**Final answer:**:
|
| 99 |
-
"""
|
| 100 |
-
|
| 101 |
-
client = OpenAI()
|
| 102 |
-
completion = client.chat.completions.create(
|
| 103 |
-
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
|
| 104 |
-
model="gpt-4o"
|
| 105 |
-
)
|
| 106 |
-
|
| 107 |
-
print("###")
|
| 108 |
-
print(completion.choices[0].message.content)
|
| 109 |
-
print("###")
|
| 110 |
-
|
| 111 |
-
return completion.choices[0].message.content
|
|
|
|
| 28 |
research_agent = Agent(
|
| 29 |
role="Web Research Agent",
|
| 30 |
goal="Search the web for question \"{topic}\" and scrape the most relevant web page.",
|
| 31 |
+
backstory="As an expert research assistant, you search the web for the question and scrape the most relevant web page.",
|
|
|
|
| 32 |
allow_delegation=False,
|
| 33 |
tools=[search_tool, web_rag_tool],
|
| 34 |
verbose=True
|
| 35 |
)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
research = Task(
|
| 38 |
agent=research_agent,
|
| 39 |
description="Search the web for question \"{topic}\" and scrape the most relevant web page.",
|
| 40 |
+
expected_output="Content to help answer the question."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
crew = Crew(
|
| 44 |
+
agents=[research_agent],
|
|
|
|
| 45 |
planning=True,
|
| 46 |
process=Process.sequential,
|
| 47 |
+
tasks=[research],
|
|
|
|
| 48 |
verbose=True
|
| 49 |
)
|
| 50 |
|
| 51 |
answer = crew().kickoff(inputs={"topic": question})
|
| 52 |
|
| 53 |
+
return final_answer(question, answer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|