sahil-datascience commited on
Commit
da071bf
·
1 Parent(s): 356d8dd
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -31,25 +31,29 @@ class BasicAgent:
31
  python_tool = PythonInterpreterTool()
32
  visit_tool = VisitWebpageTool()
33
 
 
34
 
35
  self.agent = CodeAgent(
36
  model=self.model,
37
  tools=[search_tool, wiki_tool, python_tool, visit_tool],
38
  )
39
- self.system_prompt = prompts["system"]
 
 
 
 
40
  print("BasicAgent initialized.")
41
 
42
  def __call__(self, question: str) -> str:
43
  print(f"Agent received question (first 50 chars): {question[:50]}...")
44
- messages = [
45
- {"role": "system", "content": self.system_prompt},
46
- {"role": "user", "content": question},
47
- ]
48
- answer = self.agent.run(messages)
49
- # Ensure answer is always a string, never a list
50
- if isinstance(answer, list):
51
- print(f"Warning: Agent returned a list. Converting to string. Value: {answer}")
52
- answer = " ".join(str(a) for a in answer)
53
  return answer
54
 
55
 
 
31
  python_tool = PythonInterpreterTool()
32
  visit_tool = VisitWebpageTool()
33
 
34
+
35
 
36
  self.agent = CodeAgent(
37
  model=self.model,
38
  tools=[search_tool, wiki_tool, python_tool, visit_tool],
39
  )
40
+
41
+ self.agent.PromptTemplates["final_answer"]["post_messages"] = (
42
+ code_agent.prompt_templates["final_answer"]["post_messages"] + prompts["system"]
43
+ )
44
+
45
  print("BasicAgent initialized.")
46
 
47
  def __call__(self, question: str) -> str:
48
  print(f"Agent received question (first 50 chars): {question[:50]}...")
49
+
50
+ answer = self.agent.run(question)
51
+
52
+ if isinstance(answer, str) and "Final Answer" in answer:
53
+ # Extract everything after "Final Answer"
54
+ idx = answer.find("Final Answer")
55
+ # Remove "Final Answer" and any colon or dash after it, then strip whitespace
56
+ answer = answer[idx + len("Final Answer"):].lstrip(": -").strip()
 
57
  return answer
58
 
59