bstraehle commited on
Commit
ab1c2b7
·
verified ·
1 Parent(s): 5c35603

Update crew.py

Browse files
Files changed (1) hide show
  1. crew.py +28 -2
crew.py CHANGED
@@ -20,12 +20,13 @@ tracer_provider = register(
20
  def get_crew():
21
  search_tool = SerperDevTool()
22
  web_rag_tool = WebsiteSearchTool()
 
23
 
24
  researcher = Agent(
25
  role="Web Research Agent",
26
  goal="Search the web for topic {topic} and scrape the most relevant web page.",
27
  backstory="As an expert web research assistant, you are search the web for topic {topic} and scraping the most relevant web page.",
28
- tools=[search_tool, web_rag_tool],
29
  verbose=True
30
  )
31
 
@@ -41,4 +42,29 @@ def get_crew():
41
  planning=True,
42
  process = Process.sequential,
43
  verbose=True
44
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def get_crew():
21
  search_tool = SerperDevTool()
22
  web_rag_tool = WebsiteSearchTool()
23
+ final_answer_tool = FinalAnswerTool()
24
 
25
  researcher = Agent(
26
  role="Web Research Agent",
27
  goal="Search the web for topic {topic} and scrape the most relevant web page.",
28
  backstory="As an expert web research assistant, you are search the web for topic {topic} and scraping the most relevant web page.",
29
+ tools=[search_tool, web_rag_tool, final_answer_tool],
30
  verbose=True
31
  )
32
 
 
42
  planning=True,
43
  process = Process.sequential,
44
  verbose=True
45
+ )
46
+
47
+ class FinalAnswerTool(BaseTool):
48
+ name: str ="Final Answer Tool"
49
+ description: str = ("Given a question and answer, gets the final answer.")
50
+
51
+ def _run(question, answer) -> str:
52
+ prompt_template = """
53
+ You are given a question and context. You must **precisely** answer the question based on the context. Do not include explanations, steps, reasoning, or additional text.
54
+ **Question:** """ + question + """
55
+ **Context:** """ + answer + """
56
+ **Example 1:** What is the capital of France? Paris
57
+ **Example 2:** What is the superlative of good? Best
58
+ **Example 3:** What is the opposite of left? Right
59
+ **Answer:**:
60
+ """
61
+
62
+ client = OpenAI()
63
+ completion = client.chat.completions.create(
64
+ messages = [{"role": "user",
65
+ "content": [{"type": "text",
66
+ "text": prompt_template}],
67
+ model = "gpt-4o-mini"
68
+ )
69
+
70
+ return completion.choices[0].message.content