Spaces:
Sleeping
Sleeping
Use external models.
Browse files- app.py +189 -175
- app-api.py → app.py.bak +115 -142
app.py
CHANGED
@@ -26,40 +26,53 @@ class BasicAgent:
|
|
26 |
try:
|
27 |
count = 0
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# print(f"Content for system message: {content}")
|
65 |
|
@@ -166,147 +179,148 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
166 |
|
167 |
# 2. Fetch Questions
|
168 |
print(f"Fetching questions from: {questions_url}")
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
|
|
310 |
|
311 |
# 3. Run your Agent
|
312 |
results_log = []
|
|
|
26 |
try:
|
27 |
count = 0
|
28 |
|
29 |
+
content = "You are taking a quiz. Follow the description in the question. Do do not report your thoughts, explanations, reasoning, or conclusion. Give only YOUR FINAL ANSWER. YOUR FINAL ANSWER should be a number (write the number using digits) 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, apply the above rules depending of whether the element to be put in the list is a number or a string. Remove any quotation marks surrounding the answer."
|
30 |
+
|
31 |
+
llm_api_url = "http://localhost:8004/ask"
|
32 |
+
headers = {"Content-Type": "application/json"}
|
33 |
+
payload = {"question": f"Question: {question}\n\n1. Derive the sub-questions to above question\n2. Provide answers to each sub-questions.\n3. Provide final exact answer."}
|
34 |
+
|
35 |
+
print(f"Sending question to LLM API: {llm_api_url}")
|
36 |
+
response = requests.post(llm_api_url, headers=headers, json=payload, timeout=60)
|
37 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
38 |
+
|
39 |
+
response_data = response.json()
|
40 |
+
search_results = response_data.get("answer", "No answer found in LLM response.")
|
41 |
+
print(f"LLM API response received: {search_results}")
|
42 |
+
|
43 |
+
content += f"\n\nThe following are the results from LLM, use it as reference along with your own knowledge base to provide the most accurate answer: {search_results}"
|
44 |
+
|
45 |
+
# nlp = spacy.load("en_core_web_sm")
|
46 |
+
# doc = nlp(question)
|
47 |
+
# # Extract keywords: Nouns, Proper Nouns, Adjectives, and Verbs might be useful
|
48 |
+
# keywords = [token.lemma_ for token in doc if token.pos_ in ['NOUN', 'PROPN', 'ADJ', 'VERB'] and not token.is_stop]
|
49 |
+
# # Extract all recognized entities
|
50 |
+
# entities = [ent.text for ent in doc.ents]
|
51 |
+
# print("Keywords:", keywords)
|
52 |
+
# print("Entities:", entities)
|
53 |
+
|
54 |
+
# keywords.extend(entities) # Combine keywords and entities for search
|
55 |
+
|
56 |
+
# # Call langsearch_search function
|
57 |
+
# search_query = ""
|
58 |
+
# if keywords:
|
59 |
+
# search_query = " ".join(keywords)
|
60 |
+
# # print(f"No entities found, using keywords for search query: '{search_query}'")
|
61 |
+
# else:
|
62 |
+
# search_query = question
|
63 |
+
# # print("No entities or keywords found, using original question for search query.")
|
64 |
+
# search_results = langsearch_search(query=search_query, count=5)
|
65 |
+
# if len(search_results) > 0:
|
66 |
+
# # Convert search results to a readable text format
|
67 |
+
# search_results_text = ""
|
68 |
+
# for i, result in enumerate(search_results, 1):
|
69 |
+
# count += 1
|
70 |
+
# search_results_text += f"\n\n---SEARCH RESULT #{count}---\n"
|
71 |
+
# search_results_text += f"{search_results[i - 1]}"
|
72 |
+
# content += f"\n\nThe following are the results from NLP + LangSearch, use it as reference along with your own knowledge base to provide the most accurate answer: {search_results_text}"
|
73 |
+
|
74 |
+
# search_results = langsearch_search(query=question, count=5)
|
75 |
+
# content += f"\n\nThe following are the results from the LangSearch, use it as reference along with your own knowledge base to provide the most accurate answer: {search_results}"
|
76 |
|
77 |
# print(f"Content for system message: {content}")
|
78 |
|
|
|
179 |
|
180 |
# 2. Fetch Questions
|
181 |
print(f"Fetching questions from: {questions_url}")
|
182 |
+
try:
|
183 |
+
response = requests.get(questions_url, timeout=15)
|
184 |
+
response.raise_for_status()
|
185 |
+
questions_data = response.json()
|
186 |
+
print(f"Questions: {questions_data}")
|
187 |
+
if not questions_data:
|
188 |
+
print("Fetched questions list is empty.")
|
189 |
+
return "Fetched questions list is empty or invalid format.", None
|
190 |
+
print(f"Fetched {len(questions_data)} questions.")
|
191 |
+
except requests.exceptions.RequestException as e:
|
192 |
+
print(f"Error fetching questions: {e}")
|
193 |
+
return f"Error fetching questions: {e}", None
|
194 |
+
except requests.exceptions.JSONDecodeError as e:
|
195 |
+
print(f"Error decoding JSON response from questions endpoint: {e}")
|
196 |
+
print(f"Response text: {response.text[:500]}")
|
197 |
+
return f"Error decoding server response for questions: {e}", None
|
198 |
+
except Exception as e:
|
199 |
+
print(f"An unexpected error occurred fetching questions: {e}")
|
200 |
+
return f"An unexpected error occurred fetching questions: {e}", None
|
201 |
+
|
202 |
+
# questions_data = [
|
203 |
+
# {
|
204 |
+
# 'task_id': '8e867cd7-cff9-4e6c-867a-ff5ddc2550be',
|
205 |
+
# 'question': 'How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.',
|
206 |
+
# 'Level': '1',
|
207 |
+
# 'file_name': ''
|
208 |
+
# },
|
209 |
+
# {
|
210 |
+
# 'task_id': 'a1e91b78-d3d8-4675-bb8d-62741b4b68a6',
|
211 |
+
# 'question': 'In the video https:\\/\\/www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?',
|
212 |
+
# 'Level': '1',
|
213 |
+
# 'file_name': ''
|
214 |
+
# },
|
215 |
+
# {
|
216 |
+
# 'task_id': '2d83110e-a098-4ebb-9987-066c06fa42d0',
|
217 |
+
# 'question': '.rewsna eht sa "tfel" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI',
|
218 |
+
# 'Level': '1',
|
219 |
+
# 'file_name': ''
|
220 |
+
# },
|
221 |
+
# {
|
222 |
+
# 'task_id': 'cca530fc-4052-43b2-b130-b30968d8aa44',
|
223 |
+
# 'question': "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
224 |
+
# 'Level': '1',
|
225 |
+
# 'file_name': 'cca530fc-4052-43b2-b130-b30968d8aa44.png'
|
226 |
+
# },
|
227 |
+
# {
|
228 |
+
# 'task_id': '4fc2f1ae-8625-45b5-ab34-ad4433bc21f8',
|
229 |
+
# 'question': 'Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?',
|
230 |
+
# 'Level': '1',
|
231 |
+
# 'file_name': ''
|
232 |
+
# },
|
233 |
+
# {
|
234 |
+
# 'task_id': '6f37996b-2ac7-44b0-8e68-6d28256631b4',
|
235 |
+
# 'question': 'Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.',
|
236 |
+
# 'Level': '1',
|
237 |
+
# 'file_name': ''
|
238 |
+
# },
|
239 |
+
# {
|
240 |
+
# 'task_id': '9d191bce-651d-4746-be2d-7ef8ecadb9c2',
|
241 |
+
# 'question': 'Examine the video at https:\\/\\/www.youtube.com/watch?v=1htKBjuUWec.\n\nWhat does Teal\'c say in response to the question "Isn\'t that hot?"',
|
242 |
+
# 'Level': '1',
|
243 |
+
# 'file_name': ''
|
244 |
+
# },
|
245 |
+
# {
|
246 |
+
# 'task_id': 'cabe07ed-9eca-40ea-8ead-410ef5e83f91',
|
247 |
+
# 'question': "What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?",
|
248 |
+
# 'Level': '1',
|
249 |
+
# 'file_name': ''
|
250 |
+
# },
|
251 |
+
# {
|
252 |
+
# 'task_id': '3cef3a44-215e-4aed-8e3b-b1e3f08063b7',
|
253 |
+
# 'question': "I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.",
|
254 |
+
# 'Level': '1',
|
255 |
+
# 'file_name': ''
|
256 |
+
# },
|
257 |
+
# {
|
258 |
+
# 'task_id': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3',
|
259 |
+
# 'question': 'Hi, I\'m making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I\'m not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can\'t quite make out what she\'s saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I\'ve attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for "a pinch of salt" or "two cups of ripe strawberries" the ingredients on the list would be "salt" and "ripe strawberries".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.",
|
260 |
+
# 'Level': '1',
|
261 |
+
# 'file_name': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3'
|
262 |
+
# },
|
263 |
+
# {
|
264 |
+
# 'task_id': '305ac316-eef6-4446-960a-92d80d542f82',
|
265 |
+
# 'question': 'Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.',
|
266 |
+
# 'Level': '1',
|
267 |
+
# 'file_name': ''
|
268 |
+
# },
|
269 |
+
# {
|
270 |
+
# 'task_id': 'f918266a-b3e0-4914-865d-4faa564f1aef',
|
271 |
+
# 'question': 'What is the final numeric output from the attached Python code?',
|
272 |
+
# 'Level': '1',
|
273 |
+
# 'file_name': 'f918266a-b3e0-4914-865d-4faa564f1aef.py'
|
274 |
+
# },
|
275 |
+
# {
|
276 |
+
# 'task_id': '3f57289b-8c60-48be-bd80-01f8099ca449',
|
277 |
+
# 'question': 'How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?',
|
278 |
+
# 'Level': '1',
|
279 |
+
# 'file_name': ''
|
280 |
+
# },
|
281 |
+
# {
|
282 |
+
# 'task_id': '1f975693-876d-457b-a649-393859e79bf3',
|
283 |
+
# 'question': "Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.",
|
284 |
+
# 'Level': '1',
|
285 |
+
# 'file_name': '1f975693-876d-457b-a649-393859e79bf3.mp3'
|
286 |
+
# },
|
287 |
+
# {
|
288 |
+
# 'task_id': '840bfca7-4f7b-481a-8794-c560c340185d',
|
289 |
+
# 'question': 'On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?',
|
290 |
+
# 'Level': '1',
|
291 |
+
# 'file_name': ''
|
292 |
+
# },
|
293 |
+
# {
|
294 |
+
# 'task_id': 'bda648d7-d618-4883-88f4-3466eabd860e',
|
295 |
+
# 'question': "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.",
|
296 |
+
# 'Level': '1',
|
297 |
+
# 'file_name': ''
|
298 |
+
# },
|
299 |
+
# {
|
300 |
+
# 'task_id': 'cf106601-ab4f-4af9-b045-5295fe67b37d',
|
301 |
+
# 'question': "What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.",
|
302 |
+
# 'Level': '1',
|
303 |
+
# 'file_name': ''
|
304 |
+
# },
|
305 |
+
# {
|
306 |
+
# 'task_id': 'a0c07678-e491-4bbc-8f0b-07405144218f',
|
307 |
+
# 'question': "Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.",
|
308 |
+
# 'Level': '1',
|
309 |
+
# 'file_name': ''
|
310 |
+
# },
|
311 |
+
# {
|
312 |
+
# 'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733',
|
313 |
+
# 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.',
|
314 |
+
# 'Level': '1',
|
315 |
+
# 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'
|
316 |
+
# },
|
317 |
+
# {
|
318 |
+
# 'task_id': '5a0c1adf-205e-4841-a666-7c3ef95def9d',
|
319 |
+
# 'question': 'What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?',
|
320 |
+
# 'Level': '1',
|
321 |
+
# 'file_name': ''
|
322 |
+
# },
|
323 |
+
# ]
|
324 |
|
325 |
# 3. Run your Agent
|
326 |
results_log = []
|
app-api.py → app.py.bak
RENAMED
@@ -26,67 +26,40 @@ class BasicAgent:
|
|
26 |
try:
|
27 |
count = 0
|
28 |
|
29 |
-
content = "You are
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
#
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
#
|
42 |
-
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
# # Extract all recognized entities
|
64 |
-
# entities = [ent.text for ent in doc.ents]
|
65 |
-
# print("Keywords:", keywords)
|
66 |
-
# print("Entities:", entities)
|
67 |
-
|
68 |
-
# keywords.extend(entities) # Combine keywords and entities for search
|
69 |
-
|
70 |
-
# # Call langsearch_search function
|
71 |
-
# search_query = ""
|
72 |
-
# if keywords:
|
73 |
-
# search_query = " ".join(keywords)
|
74 |
-
# # print(f"No entities found, using keywords for search query: '{search_query}'")
|
75 |
-
# else:
|
76 |
-
# search_query = question
|
77 |
-
# # print("No entities or keywords found, using original question for search query.")
|
78 |
-
# search_results = langsearch_search(query=search_query, count=5)
|
79 |
-
# if len(search_results) > 0:
|
80 |
-
# # Convert search results to a readable text format
|
81 |
-
# search_results_text = ""
|
82 |
-
# for i, result in enumerate(search_results, 1):
|
83 |
-
# count += 1
|
84 |
-
# search_results_text += f"\n\n---SEARCH RESULT #{count}---\n"
|
85 |
-
# search_results_text += f"{search_results[i - 1]}"
|
86 |
-
# content += f"\n\nThe following are the results from NLP + LangSearch, use it as reference along with your own knowledge base to provide the most accurate answer: {search_results_text}"
|
87 |
-
|
88 |
-
# search_results = langsearch_search(query=question, count=5)
|
89 |
-
# content += f"\n\nThe following are the results from the LangSearch, use it as reference along with your own knowledge base to provide the most accurate answer: {search_results}"
|
90 |
|
91 |
# print(f"Content for system message: {content}")
|
92 |
|
@@ -213,24 +186,24 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
213 |
# print(f"An unexpected error occurred fetching questions: {e}")
|
214 |
# return f"An unexpected error occurred fetching questions: {e}", None
|
215 |
questions_data = [
|
216 |
-
{
|
217 |
-
'task_id': '8e867cd7-cff9-4e6c-867a-ff5ddc2550be',
|
218 |
-
'question': 'How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.',
|
219 |
-
'Level': '1',
|
220 |
-
'file_name': ''
|
221 |
-
},
|
222 |
# {
|
223 |
-
# 'task_id': '
|
224 |
-
# 'question': '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
# 'Level': '1',
|
226 |
# 'file_name': ''
|
227 |
# },
|
228 |
-
{
|
229 |
-
'task_id': '2d83110e-a098-4ebb-9987-066c06fa42d0',
|
230 |
-
'question': '.rewsna eht sa "tfel" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI',
|
231 |
-
'Level': '1',
|
232 |
-
'file_name': ''
|
233 |
-
},
|
234 |
# {
|
235 |
# 'task_id': 'cca530fc-4052-43b2-b130-b30968d8aa44',
|
236 |
# 'question': "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
@@ -243,96 +216,96 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
243 |
'Level': '1',
|
244 |
'file_name': ''
|
245 |
},
|
246 |
-
{
|
247 |
-
'task_id': '6f37996b-2ac7-44b0-8e68-6d28256631b4',
|
248 |
-
'question': 'Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.',
|
249 |
-
'Level': '1',
|
250 |
-
'file_name': ''
|
251 |
-
},
|
252 |
# {
|
253 |
-
#
|
254 |
-
#
|
255 |
-
#
|
256 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
# },
|
258 |
-
{
|
259 |
-
'task_id': 'cabe07ed-9eca-40ea-8ead-410ef5e83f91',
|
260 |
-
'question': "What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?",
|
261 |
-
'Level': '1',
|
262 |
-
'file_name': ''
|
263 |
-
},
|
264 |
-
{
|
265 |
-
'task_id': '3cef3a44-215e-4aed-8e3b-b1e3f08063b7',
|
266 |
-
'question': "I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.",
|
267 |
-
'Level': '1',
|
268 |
-
'file_name': ''
|
269 |
-
},
|
270 |
# {
|
271 |
# 'task_id': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3',
|
272 |
# 'question': 'Hi, I\'m making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I\'m not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can\'t quite make out what she\'s saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I\'ve attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for "a pinch of salt" or "two cups of ripe strawberries" the ingredients on the list would be "salt" and "ripe strawberries".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.",
|
273 |
# 'Level': '1',
|
274 |
# 'file_name': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3'
|
275 |
# },
|
276 |
-
{
|
277 |
-
'task_id': '305ac316-eef6-4446-960a-92d80d542f82',
|
278 |
-
'question': 'Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.',
|
279 |
-
'Level': '1',
|
280 |
-
'file_name': ''
|
281 |
-
},
|
282 |
# {
|
283 |
-
#
|
284 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
# 'Level': '1',
|
286 |
-
# 'file_name': '
|
287 |
# },
|
288 |
-
{
|
289 |
-
'task_id': '3f57289b-8c60-48be-bd80-01f8099ca449',
|
290 |
-
'question': 'How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?',
|
291 |
-
'Level': '1',
|
292 |
-
'file_name': ''
|
293 |
-
},
|
294 |
# {
|
295 |
# 'task_id': '1f975693-876d-457b-a649-393859e79bf3',
|
296 |
# 'question': "Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.",
|
297 |
# 'Level': '1',
|
298 |
# 'file_name': '1f975693-876d-457b-a649-393859e79bf3.mp3'
|
299 |
# },
|
300 |
-
{
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
},
|
306 |
-
{
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
},
|
312 |
-
{
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
},
|
318 |
-
{
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
},
|
324 |
# {
|
325 |
# 'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733',
|
326 |
# 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.',
|
327 |
# 'Level': '1',
|
328 |
# 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'
|
329 |
# },
|
330 |
-
{
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
},
|
336 |
]
|
337 |
|
338 |
# 3. Run your Agent
|
|
|
26 |
try:
|
27 |
count = 0
|
28 |
|
29 |
+
# content = "You are an assistant that has access to the following set of tools. Read the question carefully and do not report your thoughts, explanations, reasoning, or conclusion. Always use RAG. If you know the answer, give only 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. 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, apply the above rules depending of whether the element to be put in the list is a number or a string. On the other hand, if you really don't know the answer after your best efforts, break down the question and list all search queries in a string array."
|
30 |
+
content = "You are a news researcher that has access to the following set of tools. Read the question carefully. Do do not report your thoughts, explanations, reasoning, or conclusion. Do not reason too long. Give only 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. 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, apply the above rules depending of whether the element to be put in the list is a number or a string. If you don't have complete certainty, you must still provide your best answer based on the information available to you. Always provide an answer rather than no answer, use your best judgment to determine the most likely correct response."
|
31 |
+
|
32 |
+
nlp = spacy.load("en_core_web_sm")
|
33 |
+
doc = nlp(question)
|
34 |
+
# Extract keywords: Nouns, Proper Nouns, Adjectives, and Verbs might be useful
|
35 |
+
keywords = [token.lemma_ for token in doc if token.pos_ in ['NOUN', 'PROPN', 'ADJ', 'VERB'] and not token.is_stop]
|
36 |
+
# Extract all recognized entities
|
37 |
+
entities = [ent.text for ent in doc.ents]
|
38 |
+
print("Keywords:", keywords)
|
39 |
+
print("Entities:", entities)
|
40 |
+
|
41 |
+
keywords.extend(entities) # Combine keywords and entities for search
|
42 |
+
|
43 |
+
# Call langsearch_search function
|
44 |
+
search_query = ""
|
45 |
+
if keywords:
|
46 |
+
search_query = " ".join(keywords)
|
47 |
+
# print(f"No entities found, using keywords for search query: '{search_query}'")
|
48 |
+
else:
|
49 |
+
search_query = question
|
50 |
+
# print("No entities or keywords found, using original question for search query.")
|
51 |
+
search_results = langsearch_search(query=search_query, count=5)
|
52 |
+
if len(search_results) > 0:
|
53 |
+
# Convert search results to a readable text format
|
54 |
+
search_results_text = ""
|
55 |
+
for i, result in enumerate(search_results, 1):
|
56 |
+
count += 1
|
57 |
+
search_results_text += f"\n\n---SEARCH RESULT #{count}---\n"
|
58 |
+
search_results_text += f"{search_results[i - 1]}"
|
59 |
+
content += f"\n\nThe following are the results from the NLP wutg LangSearch, use it as reference along with your own knowledge base to provide the most accurate answer: {search_results_text}"
|
60 |
+
|
61 |
+
search_results = langsearch_search(query=question, count=5)
|
62 |
+
content += f"\n\nThe following are the results from the LangSearch, use it as reference along with your own knowledge base to provide the most accurate answer: {search_results}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# print(f"Content for system message: {content}")
|
65 |
|
|
|
186 |
# print(f"An unexpected error occurred fetching questions: {e}")
|
187 |
# return f"An unexpected error occurred fetching questions: {e}", None
|
188 |
questions_data = [
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
# {
|
190 |
+
# 'task_id': '8e867cd7-cff9-4e6c-867a-ff5ddc2550be',
|
191 |
+
# 'question': 'How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.',
|
192 |
+
# 'Level': '1',
|
193 |
+
# 'file_name': ''
|
194 |
+
# },
|
195 |
+
# {
|
196 |
+
# 'task_id': 'a1e91b78-d3d8-4675-bb8d-62741b4b68a6',
|
197 |
+
# 'question': 'In the video https:\\/\\/www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?',
|
198 |
+
# 'Level': '1',
|
199 |
+
# 'file_name': ''
|
200 |
+
# },
|
201 |
+
# {
|
202 |
+
# 'task_id': '2d83110e-a098-4ebb-9987-066c06fa42d0',
|
203 |
+
# 'question': '.rewsna eht sa "tfel" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI',
|
204 |
# 'Level': '1',
|
205 |
# 'file_name': ''
|
206 |
# },
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
# {
|
208 |
# 'task_id': 'cca530fc-4052-43b2-b130-b30968d8aa44',
|
209 |
# 'question': "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
|
|
216 |
'Level': '1',
|
217 |
'file_name': ''
|
218 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
# {
|
220 |
+
# 'task_id': '6f37996b-2ac7-44b0-8e68-6d28256631b4',
|
221 |
+
# 'question': 'Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.',
|
222 |
+
# 'Level': '1',
|
223 |
+
# 'file_name': ''
|
224 |
+
# },
|
225 |
+
# {
|
226 |
+
# 'task_id': '9d191bce-651d-4746-be2d-7ef8ecadb9c2',
|
227 |
+
# 'question': 'Examine the video at https:\\/\\/www.youtube.com/watch?v=1htKBjuUWec.\n\nWhat does Teal\'c say in response to the question "Isn\'t that hot?"',
|
228 |
+
# 'Level': '1',
|
229 |
+
# 'file_name': ''
|
230 |
+
# },
|
231 |
+
# {
|
232 |
+
# 'task_id': 'cabe07ed-9eca-40ea-8ead-410ef5e83f91',
|
233 |
+
# 'question': "What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?",
|
234 |
+
# 'Level': '1',
|
235 |
+
# 'file_name': ''
|
236 |
+
# },
|
237 |
+
# {
|
238 |
+
# 'task_id': '3cef3a44-215e-4aed-8e3b-b1e3f08063b7',
|
239 |
+
# 'question': "I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.",
|
240 |
+
# 'Level': '1',
|
241 |
+
# 'file_name': ''
|
242 |
# },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
# {
|
244 |
# 'task_id': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3',
|
245 |
# 'question': 'Hi, I\'m making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I\'m not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can\'t quite make out what she\'s saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I\'ve attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for "a pinch of salt" or "two cups of ripe strawberries" the ingredients on the list would be "salt" and "ripe strawberries".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.",
|
246 |
# 'Level': '1',
|
247 |
# 'file_name': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3'
|
248 |
# },
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
# {
|
250 |
+
# 'task_id': '305ac316-eef6-4446-960a-92d80d542f82',
|
251 |
+
# 'question': 'Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.',
|
252 |
+
# 'Level': '1',
|
253 |
+
# 'file_name': ''
|
254 |
+
# },
|
255 |
+
# {
|
256 |
+
# 'task_id': 'f918266a-b3e0-4914-865d-4faa564f1aef',
|
257 |
+
# 'question': 'What is the final numeric output from the attached Python code?',
|
258 |
+
# 'Level': '1',
|
259 |
+
# 'file_name': 'f918266a-b3e0-4914-865d-4faa564f1aef.py'
|
260 |
+
# },
|
261 |
+
# {
|
262 |
+
# 'task_id': '3f57289b-8c60-48be-bd80-01f8099ca449',
|
263 |
+
# 'question': 'How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?',
|
264 |
# 'Level': '1',
|
265 |
+
# 'file_name': ''
|
266 |
# },
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
# {
|
268 |
# 'task_id': '1f975693-876d-457b-a649-393859e79bf3',
|
269 |
# 'question': "Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.",
|
270 |
# 'Level': '1',
|
271 |
# 'file_name': '1f975693-876d-457b-a649-393859e79bf3.mp3'
|
272 |
# },
|
273 |
+
# {
|
274 |
+
# 'task_id': '840bfca7-4f7b-481a-8794-c560c340185d',
|
275 |
+
# 'question': 'On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?',
|
276 |
+
# 'Level': '1',
|
277 |
+
# 'file_name': ''
|
278 |
+
# },
|
279 |
+
# {
|
280 |
+
# 'task_id': 'bda648d7-d618-4883-88f4-3466eabd860e',
|
281 |
+
# 'question': "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.",
|
282 |
+
# 'Level': '1',
|
283 |
+
# 'file_name': ''
|
284 |
+
# },
|
285 |
+
# {
|
286 |
+
# 'task_id': 'cf106601-ab4f-4af9-b045-5295fe67b37d',
|
287 |
+
# 'question': "What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.",
|
288 |
+
# 'Level': '1',
|
289 |
+
# 'file_name': ''
|
290 |
+
# },
|
291 |
+
# {
|
292 |
+
# 'task_id': 'a0c07678-e491-4bbc-8f0b-07405144218f',
|
293 |
+
# 'question': "Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.",
|
294 |
+
# 'Level': '1',
|
295 |
+
# 'file_name': ''
|
296 |
+
# },
|
297 |
# {
|
298 |
# 'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733',
|
299 |
# 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.',
|
300 |
# 'Level': '1',
|
301 |
# 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'
|
302 |
# },
|
303 |
+
# {
|
304 |
+
# 'task_id': '5a0c1adf-205e-4841-a666-7c3ef95def9d',
|
305 |
+
# 'question': 'What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?',
|
306 |
+
# 'Level': '1',
|
307 |
+
# 'file_name': ''
|
308 |
+
# },
|
309 |
]
|
310 |
|
311 |
# 3. Run your Agent
|