bstraehle's picture
Update util.py
8dde8b1 verified
raw
history blame
1.96 kB
import pandas as pd
from openai import OpenAI
FILE_NAME = "data/gaia_validation_20.jsonl"
def get_questions():
df = pd.read_json(FILE_NAME, lines=True)
result=[]
for index, row in df.iterrows():
result.append([row["Level"], row["Question"], row["file_name"], row["Final answer"]])
return result
def get_final_answer(question, initial_answer):
prompt_template = """
You are an expert GAIA benchmark question answering assistant, given a question and an initial answer.
Your final answer must be a number and/or string 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.
**Question:** """ + question + """
**Initial answer:** """ + initial_answer + """
**Example 1:** How many 'r' are in strawberry? 3
**Example 2:** What is the opposite of white? Black
**Example 3:** What is the biggest city in California? Los Angeles
**Example 4:** What is the superlative of good? Best
**Example 5:** How many states are in the USA? 50
**Final answer:**
"""
client = OpenAI()
completion = client.chat.completions.create(
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
model="gpt-4.5-preview"
)
final_answer = completion.choices[0].message.content
print("###")
print(question)
print(initial_answer)
print(final_answer)
print("###")
return final_answer