File size: 1,051 Bytes
8c269dc 960e946 ee7a47a 960e946 8c269dc ee7a47a 8c269dc 960e946 8c269dc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import pandas as pd
import os
class CSVSCache:
def __init__(self, filename="results.csv"):
self.filename = filename
self.df = self._load_cache()
def _load_cache(self):
if os.path.exists(self.filename):
return pd.read_csv(self.filename)
return pd.DataFrame(columns=["task_id", "question", "answer"])
def _save_cache(self):
self.df.to_csv(self.filename, index=False)
def get_all_entries(self):
return self.df
def get_answer(self, question):
match = self.df[self.df['question'] == question].head()
# Check if any matches were found
if not match.empty:
return match['answer'].iloc[0]
else:
return "unknown"
def main():
csv = CSVSCache()
print("done")
q = "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations."
print(csv.get_answer(q))
if __name__ == "__main__":
main()
|