Update app.py
Browse files
app.py
CHANGED
|
@@ -64,7 +64,7 @@ class BasicAgent:
|
|
| 64 |
max_print_outputs_length=100,
|
| 65 |
)
|
| 66 |
|
| 67 |
-
def __call__(self, question: str) -> str:
|
| 68 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 69 |
prompt = (
|
| 70 |
"You are a general AI assistant. I will ask you a question. "
|
|
@@ -75,14 +75,14 @@ class BasicAgent:
|
|
| 75 |
"(3) If a web search is needed and the answer is likely on Wikipedia, try using the wiki_url_tool to find the relevant page; "
|
| 76 |
"if that fails, search manually; if you read a wikipedia page, always use the wiki_tool to extract data from Wikipedia tables. They may be usefull to answer the questions. "
|
| 77 |
"(4) Never use synonyms not present in the question. "
|
| 78 |
-
"(5) If
|
| 79 |
"(6) If you need to know the list of vegetables, you will find it with vegetable_info_retriever."
|
| 80 |
"Never make assumptions to answer a question. . If you do not know the answer, say so clearly. Always report your thoughts and finish your answer with the following template: "
|
| 81 |
"FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
|
| 82 |
"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. "
|
| 83 |
"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. "
|
| 84 |
"If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. "
|
| 85 |
-
f"Here are the questions : {question}"
|
| 86 |
)
|
| 87 |
answer = self.alfred.run(prompt)
|
| 88 |
print(f"Agent returning fixed answer: {answer}")
|
|
@@ -146,11 +146,12 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 146 |
for item in questions_data:
|
| 147 |
task_id = item.get("task_id")
|
| 148 |
question_text = item.get("question")
|
|
|
|
| 149 |
if not task_id or question_text is None:
|
| 150 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 151 |
continue
|
| 152 |
try:
|
| 153 |
-
submitted_answer = agent(question_text)
|
| 154 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 155 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 156 |
except Exception as e:
|
|
|
|
| 64 |
max_print_outputs_length=100,
|
| 65 |
)
|
| 66 |
|
| 67 |
+
def __call__(self, question: str,file_name: str) -> str:
|
| 68 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 69 |
prompt = (
|
| 70 |
"You are a general AI assistant. I will ask you a question. "
|
|
|
|
| 75 |
"(3) If a web search is needed and the answer is likely on Wikipedia, try using the wiki_url_tool to find the relevant page; "
|
| 76 |
"if that fails, search manually; if you read a wikipedia page, always use the wiki_tool to extract data from Wikipedia tables. They may be usefull to answer the questions. "
|
| 77 |
"(4) Never use synonyms not present in the question. "
|
| 78 |
+
"(5) The questions may have file attached. If it contains an image, use image_tool to describe it. If it contains an mp3 audio, use audio_tool to translate it to text."
|
| 79 |
"(6) If you need to know the list of vegetables, you will find it with vegetable_info_retriever."
|
| 80 |
"Never make assumptions to answer a question. . If you do not know the answer, say so clearly. Always report your thoughts and finish your answer with the following template: "
|
| 81 |
"FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
|
| 82 |
"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. "
|
| 83 |
"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. "
|
| 84 |
"If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. "
|
| 85 |
+
f"Here are the questions : {question} and the attached file (may be empty, hence it means no attached file for this question) {file_name}"
|
| 86 |
)
|
| 87 |
answer = self.alfred.run(prompt)
|
| 88 |
print(f"Agent returning fixed answer: {answer}")
|
|
|
|
| 146 |
for item in questions_data:
|
| 147 |
task_id = item.get("task_id")
|
| 148 |
question_text = item.get("question")
|
| 149 |
+
file_name=item.get("file_name")
|
| 150 |
if not task_id or question_text is None:
|
| 151 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 152 |
continue
|
| 153 |
try:
|
| 154 |
+
submitted_answer = agent(question_text,file_name)
|
| 155 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 156 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 157 |
except Exception as e:
|