Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -150,29 +150,29 @@ class BasicAgent:
|
|
| 150 |
)
|
| 151 |
|
| 152 |
def __call__(self, question: str, task_id: str = "") -> str:
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
Return ONLY the final answer with no explanation, no punctuation, no extra words.
|
| 156 |
-
- If the answer is a number, return just the number.
|
| 157 |
-
- If the answer is a name, return just the name.
|
| 158 |
-
- If the answer is a list, return comma separated values in alphabetical order.
|
| 159 |
-
- If the question asks about a YouTube video, use the youtube_transcript tool.
|
| 160 |
-
- If the question mentions Wikipedia, use the wikipedia_search tool.
|
| 161 |
-
- If the question references an attached file, use download_file with the task_id below.
|
| 162 |
-
Task ID: {task_id}
|
| 163 |
-
|
| 164 |
-
Question: {question}"""
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
|
| 177 |
|
| 178 |
# --- Main Evaluation Function ---
|
|
|
|
| 150 |
)
|
| 151 |
|
| 152 |
def __call__(self, question: str, task_id: str = "") -> str:
|
| 153 |
+
try:
|
| 154 |
+
prompt = f"""Answer the following question accurately.
|
| 155 |
+
Return ONLY the final answer with no explanation, no punctuation, no extra words.
|
| 156 |
+
- If the answer is a number, return just the number.
|
| 157 |
+
- If the answer is a name, return just the name.
|
| 158 |
+
- If the answer is a list, return comma separated values in alphabetical order.
|
| 159 |
+
- If the question asks about a YouTube video, use the youtube_transcript tool.
|
| 160 |
+
- If the question mentions Wikipedia, use the wikipedia_search tool.
|
| 161 |
+
- If the question references an attached file, use download_file with the task_id below.
|
| 162 |
+
Task ID: {task_id}
|
| 163 |
+
|
| 164 |
+
Question: {question}"""
|
| 165 |
+
result = self.agent.run(prompt)
|
| 166 |
+
# handle case where result is a list of content blocks
|
| 167 |
+
if isinstance(result, list):
|
| 168 |
+
for block in result:
|
| 169 |
+
if isinstance(block, dict) and block.get('type') == 'text':
|
| 170 |
+
return block['text'].strip()
|
| 171 |
+
return str(result).strip()
|
| 172 |
+
except Exception as e:
|
| 173 |
+
err = str(e)
|
| 174 |
+
print(f"Agent error: {err}")
|
| 175 |
+
return "I don't know"
|
| 176 |
|
| 177 |
|
| 178 |
# --- Main Evaluation Function ---
|