Sagar Sanghani commited on
Commit
ee7a47a
·
1 Parent(s): 73cd47f

updates cache with gemini which seems to be much better

Browse files
Files changed (3) hide show
  1. csv_cache.py +6 -5
  2. model.py +21 -7
  3. results.csv +5 -5
csv_cache.py CHANGED
@@ -18,14 +18,15 @@ class CSVSCache:
18
  return self.df
19
 
20
  def get_answer(self, question):
21
- if question in self.df.index:
22
- answer = self.df.loc[question, 'answer']
23
- if pd.isna(answer) or answer == "unknown":
24
- return "unknown"
25
- return str(answer)
26
  else:
27
  return "unknown"
28
 
 
29
  def main():
30
  csv = CSVSCache()
31
 
 
18
  return self.df
19
 
20
  def get_answer(self, question):
21
+ match = self.df[self.df['question'] == question].head()
22
+
23
+ # Check if any matches were found
24
+ if not match.empty:
25
+ return match['answer'].iloc[0]
26
  else:
27
  return "unknown"
28
 
29
+
30
  def main():
31
  csv = CSVSCache()
32
 
model.py CHANGED
@@ -64,20 +64,33 @@ class LLMProvider(Enum):
64
  corresponding environment variable names for API keys.
65
  """
66
  HUGGINGFACE = ("HuggingFace", "HF_TOKEN")
67
- HUGGINGFACE_LLAMA = ("HUGGINGFACE_LLAMA", "HF_TOKEN")
68
- GOOGLE_GEMINI = ("Google Gemini", "GOOGLE_API_KEY")
 
 
 
 
 
 
 
 
69
 
70
  class Model:
71
- def __init__(self, provider: LLMProvider = LLMProvider.HUGGINGFACE):
72
  load_dotenv(find_dotenv())
73
  self.system_prompt = get_prompt()
74
  print(f"system_prompt: {self.system_prompt}")
75
- self.provider = provider
76
  self.agent_executor = self.setup_model()
77
-
78
-
79
 
80
  def get_answer(self, question: str) -> str:
 
 
 
 
 
81
  try:
82
  result = self.agent_executor.invoke({"input": question})
83
  except BaseException as e:
@@ -202,7 +215,8 @@ def main():
202
  load_dotenv(find_dotenv())
203
  csv = CSVSCache()
204
  df = csv.get_all_entries()
205
- model = Model(LLMProvider.HUGGINGFACE_LLAMA)
 
206
  #update_mode(model)
207
  test_questions = [0, 6, 10, 12, 15]
208
  for row in test_questions:
 
64
  corresponding environment variable names for API keys.
65
  """
66
  HUGGINGFACE = ("HuggingFace", "HF_TOKEN")
67
+ HUGGINGFACE_LLAMA = ("HuggingFace_Llama", "HF_TOKEN")
68
+ GOOGLE_GEMINI = ("Google_Gemini", "GOOGLE_API_KEY")
69
+
70
+ @classmethod
71
+ def from_env(cls):
72
+ env_provider_name = os.getenv("LLM_PROVIDER", "HUGGINGFACE")
73
+ try:
74
+ return cls[env_provider_name]
75
+ except KeyError:
76
+ return cls.HUGGINGFACE
77
 
78
  class Model:
79
+ def __init__(self, useCache = True):
80
  load_dotenv(find_dotenv())
81
  self.system_prompt = get_prompt()
82
  print(f"system_prompt: {self.system_prompt}")
83
+ self.provider = LLMProvider.from_env()
84
  self.agent_executor = self.setup_model()
85
+ self.cache = CSVSCache()
86
+ self.useCache = os.getenv("USE_CACHE", True)
87
 
88
  def get_answer(self, question: str) -> str:
89
+
90
+ # Check the cache first
91
+ if self.useCache and self.cache.get_answer(question) != "unknown":
92
+ return self.cache.get_answer(question)
93
+
94
  try:
95
  result = self.agent_executor.invoke({"input": question})
96
  except BaseException as e:
 
215
  load_dotenv(find_dotenv())
216
  csv = CSVSCache()
217
  df = csv.get_all_entries()
218
+
219
+ model = Model(LLMProvider.HUGGINGFACE)
220
  #update_mode(model)
221
  test_questions = [0, 6, 10, 12, 15]
222
  for row in test_questions:
results.csv CHANGED
@@ -3,7 +3,7 @@ task_id,question,answer
3
  a1e91b78-d3d8-4675-bb8d-62741b4b68a6,"In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?",47
4
  2d83110e-a098-4ebb-9987-066c06fa42d0,".rewsna eht sa ""tfel"" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI",right
5
  cca530fc-4052-43b2-b130-b30968d8aa44,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.,I cannot view images or analyze chess positions from images. Please describe the position in text or provide a FEN string for analysis.
6
- 4fc2f1ae-8625-45b5-ab34-ad4433bc21f8,Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?,Tvx1
7
  6f37996b-2ac7-44b0-8e68-6d28256631b4,"Given this table defining * on the set S = {a, b, c, d, e}
8
 
9
  |*|a|b|c|d|e|
@@ -23,7 +23,7 @@ cabe07ed-9eca-40ea-8ead-410ef5e83f91,What is the surname of the equine veterinar
23
 
24
  milk, 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
25
 
26
- I 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.","broccoli, celery, fresh basil, lettuce, sweet potatoes"
27
  99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3,"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.
28
 
29
  In 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"".
@@ -35,9 +35,9 @@ f918266a-b3e0-4914-865d-4faa564f1aef,What is the final numeric output from the a
35
  1f975693-876d-457b-a649-393859e79bf3,"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 :(
36
 
37
  Could 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.","I'm unable to access or process audio files, including Homework.mp3, as I don't have the capability to listen to or transcribe audio recordings. Please ask a classmate or friend to read the page numbers to you, or check your course materials directly."
38
- 840bfca7-4f7b-481a-8794-c560c340185d,"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?",80NSSC21K0321
39
- bda648d7-d618-4883-88f4-3466eabd860e,Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.,Moscow
40
- cf106601-ab4f-4af9-b045-5295fe67b37d,"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.",BOL
41
  a0c07678-e491-4bbc-8f0b-07405144218f,"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.","Tsuru, Sato"
42
  7bd855d8-463d-4ed5-93ca-5fe35145f733,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.,No Excel file was attached. Please provide the data or check if the file was properly uploaded.
43
  5a0c1adf-205e-4841-a666-7c3ef95def9d,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?,Dmitri
 
3
  a1e91b78-d3d8-4675-bb8d-62741b4b68a6,"In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?",47
4
  2d83110e-a098-4ebb-9987-066c06fa42d0,".rewsna eht sa ""tfel"" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI",right
5
  cca530fc-4052-43b2-b130-b30968d8aa44,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.,I cannot view images or analyze chess positions from images. Please describe the position in text or provide a FEN string for analysis.
6
+ 4fc2f1ae-8625-45b5-ab34-ad4433bc21f8,Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?,FunkMonk
7
  6f37996b-2ac7-44b0-8e68-6d28256631b4,"Given this table defining * on the set S = {a, b, c, d, e}
8
 
9
  |*|a|b|c|d|e|
 
23
 
24
  milk, 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
25
 
26
+ I 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.","broccoli, celery, lettuce, sweet potatoes, zucchini"
27
  99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3,"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.
28
 
29
  In 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"".
 
35
  1f975693-876d-457b-a649-393859e79bf3,"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 :(
36
 
37
  Could 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.","I'm unable to access or process audio files, including Homework.mp3, as I don't have the capability to listen to or transcribe audio recordings. Please ask a classmate or friend to read the page numbers to you, or check your course materials directly."
38
+ 840bfca7-4f7b-481a-8794-c560c340185d,"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?",80GSFC21M0002
39
+ bda648d7-d618-4883-88f4-3466eabd860e,Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.,Saint Petersburg
40
+ cf106601-ab4f-4af9-b045-5295fe67b37d,"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.",CUB
41
  a0c07678-e491-4bbc-8f0b-07405144218f,"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.","Tsuru, Sato"
42
  7bd855d8-463d-4ed5-93ca-5fe35145f733,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.,No Excel file was attached. Please provide the data or check if the file was properly uploaded.
43
  5a0c1adf-205e-4841-a666-7c3ef95def9d,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?,Dmitri