JPM34 commited on
Commit
09ab61d
·
1 Parent(s): 12eb477

update call function to return llm answer instead of default answer

Browse files
Files changed (1) hide show
  1. agent.py +44 -4
agent.py CHANGED
@@ -61,10 +61,50 @@ class BasicAgent:
61
  print("BasicAgent initialized.")
62
 
63
  def __call__(self, question: str) -> str:
64
- print(f"Agent received question (first 50 chars): {question[:50]}...")
65
- fixed_answer = "This is a default answer."
66
- print(f"Agent returning fixed answer: {fixed_answer}")
67
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  def answer_question(
70
  self, question: str, task_file_path: Optional[str] = None
 
61
  print("BasicAgent initialized.")
62
 
63
  def __call__(self, question: str) -> str:
64
+ """
65
+ Process a GAIA benchmark question and return the answer
66
+
67
+ Args:
68
+ question: The question to answer
69
+ task_file_path: Optional path to a file associated with the question
70
+
71
+ Returns:
72
+ The answer to the question
73
+ """
74
+ try:
75
+ if self.verbose:
76
+ print(f"Processing question: {question}")
77
+
78
+ # Create a context with file information if available
79
+ context = question
80
+ if question.startswith(".") or ".rewsna eht sa" in question:
81
+ context = f""" This question appears to be in reversed text. Here's the reversed version: {question[::-1]} Now answer the question above. Remember to format your answer exactly as requested. """
82
+
83
+ # Add a prompt to ensure precise answers
84
+
85
+ full_prompt = f"""{context}. When answering, provide ONLY the precise answer requested. Do not include explanations, steps, reasoning, or additional text. Be direct and specific. GAIA benchmark requires exact matching answers. For example, if asked "What is the capital of France?", respond simply with "Paris"."""
86
+
87
+ # rules = "When answering, your answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. If you are asked for a comma separated list, do not include brackets and apply the above rules depending of whether the element to be put in the list is a number or a string."
88
+
89
+ # full_prompt = f"""{context}. {rules}"""
90
+
91
+ # Run the agent with the question
92
+ answer = self.agent.run(full_prompt)
93
+
94
+ # Clean up the answer to ensure it's in the expected format
95
+ # Remove common prefixes that models often add
96
+ answer = self._clean_answer(answer)
97
+
98
+ if self.verbose:
99
+ print(f"Generated answer: {answer}")
100
+
101
+ return answer
102
+
103
+ except Exception as e:
104
+ error_msg = f"Error answering question: {e}"
105
+ if self.verbose:
106
+ print(error_msg)
107
+ return error_msg
108
 
109
  def answer_question(
110
  self, question: str, task_file_path: Optional[str] = None