bstraehle's picture
Update util.py
e12492d verified
raw
history blame
1.83 kB
import pandas as pd
from openai import OpenAI
FILE_NAME = "data/gaia_validation_20.jsonl"
FINAL_ANSWER_MODEL = "gpt-4.5-preview"
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 question answering assistant. Given a question and an initial answer, your task is to determine the final answer.
**Instructions:**
- 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.
- In case of a single word answer, start the word with an uppercase letter.
**Question:** """
question + """
**Initial answer:** """
initial_answer + """
**Final answer:**
"""
client = OpenAI()
completion = client.chat.completions.create(
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
model=FINAL_ANSWER_MODEL
)
final_answer = completion.choices[0].message.content
print("###")
print(question)
print(initial_answer)
print(final_answer)
print("###")
return final_answer