cowrycode commited on
Commit
f855549
·
verified ·
1 Parent(s): c4a9bfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -14,7 +14,8 @@ from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_too
14
  #from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool
15
  from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool, transcribe_audio_tool, excel_food_sales_sum_tool, parse_file_and_summarize_tool, solve_chess_image_tool, vegetable_classifier_tool
16
  from agent import smart_agent
17
- from llama_index.llms.openai import OpenAI
 
18
  #-----------------------------------------------------------------
19
 
20
 
@@ -33,7 +34,9 @@ class BasicAgent:
33
  self.system_prompt = (
34
  "You are a helpful AI assistant completing GAIA benchmark tasks.\n"
35
  "You MUST use the tools provided when needed.\n"
36
- "If you already have enough information, respond directly and stop reasoning and do not call any tool.:\n"
 
 
37
  )
38
  self.llm = OpenAI(model="gpt-4o", temperature=0.1, api_key=OpenAI_key)
39
  # self.system_prompt = (
@@ -62,6 +65,10 @@ class BasicAgent:
62
  llm=self.llm,
63
  system_prompt=self.system_prompt,
64
  )
 
 
 
 
65
  async def run(self, question: str) -> str:
66
  print(f"Agent received question (first 50 chars): {question[:50]}...")
67
  # answer = await self.agent.run(question)
@@ -69,7 +76,8 @@ class BasicAgent:
69
  f"{question}\n\nIf you have enough information, respond with a concise final answer.",
70
  max_iterations=10
71
  )
72
- return str(answer)
 
73
  # if hasattr(answer, "output"):
74
  # print(f"Agent returning answer: {answer}")
75
  # return str(answer.output)
 
14
  #from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool
15
  from multiple_tools import round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool, wikipedia_search_tool, transcribe_audio_tool, excel_food_sales_sum_tool, parse_file_and_summarize_tool, solve_chess_image_tool, vegetable_classifier_tool
16
  from agent import smart_agent
17
+ from llama_index.llms.openai import
18
+ import re
19
  #-----------------------------------------------------------------
20
 
21
 
 
34
  self.system_prompt = (
35
  "You are a helpful AI assistant completing GAIA benchmark tasks.\n"
36
  "You MUST use the tools provided when needed.\n"
37
+ "If you already have enough information, respond directly with:\n"
38
+ "<answer>\n"
39
+ "Once you output '<answer>', stop reasoning and do not call any tool.\n"
40
  )
41
  self.llm = OpenAI(model="gpt-4o", temperature=0.1, api_key=OpenAI_key)
42
  # self.system_prompt = (
 
65
  llm=self.llm,
66
  system_prompt=self.system_prompt,
67
  )
68
+ def extract_answer(text: str) -> str:
69
+ match = re.search(r"(?<=<answer>)(.*?)(?=</answer>)", text)
70
+ return match.group(1) if match else ""
71
+
72
  async def run(self, question: str) -> str:
73
  print(f"Agent received question (first 50 chars): {question[:50]}...")
74
  # answer = await self.agent.run(question)
 
76
  f"{question}\n\nIf you have enough information, respond with a concise final answer.",
77
  max_iterations=10
78
  )
79
+ #return str(answer)
80
+ return self.extract_answer(answer);
81
  # if hasattr(answer, "output"):
82
  # print(f"Agent returning answer: {answer}")
83
  # return str(answer.output)