Spaces:
Configuration error
Configuration error
Update util.py
Browse files
util.py
CHANGED
|
@@ -4,6 +4,8 @@ from openai import OpenAI
|
|
| 4 |
|
| 5 |
FILE_NAME = "data/gaia_validation_20.jsonl"
|
| 6 |
|
|
|
|
|
|
|
| 7 |
def get_questions():
|
| 8 |
df = pd.read_json(FILE_NAME, lines=True)
|
| 9 |
result=[]
|
|
@@ -15,25 +17,35 @@ def get_questions():
|
|
| 15 |
|
| 16 |
def get_final_answer(question, initial_answer):
|
| 17 |
prompt_template = """
|
| 18 |
-
You are an expert
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
If you are asked for a
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
**Example 1:** How many 'r' are in strawberry? 3
|
| 26 |
**Example 2:** What is the opposite of white? Black
|
| 27 |
**Example 3:** What is the biggest city in California? Los Angeles
|
| 28 |
**Example 4:** What is the superlative of good? Best
|
| 29 |
**Example 5:** How many states are in the USA? 50
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
"""
|
| 32 |
|
| 33 |
client = OpenAI()
|
| 34 |
completion = client.chat.completions.create(
|
| 35 |
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
|
| 36 |
-
model=
|
| 37 |
)
|
| 38 |
|
| 39 |
final_answer = completion.choices[0].message.content
|
|
|
|
| 4 |
|
| 5 |
FILE_NAME = "data/gaia_validation_20.jsonl"
|
| 6 |
|
| 7 |
+
FINAL_ANSWER_MODEL = "gpt-4.5-preview"
|
| 8 |
+
|
| 9 |
def get_questions():
|
| 10 |
df = pd.read_json(FILE_NAME, lines=True)
|
| 11 |
result=[]
|
|
|
|
| 17 |
|
| 18 |
def get_final_answer(question, initial_answer):
|
| 19 |
prompt_template = """
|
| 20 |
+
You are an expert question answering assistant. Given a question and an initial answer, your task is to determine the final answer.
|
| 21 |
+
|
| 22 |
+
**Instructions:**
|
| 23 |
+
- 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.
|
| 24 |
+
- 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.
|
| 25 |
+
- 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.
|
| 26 |
+
- 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.
|
| 27 |
+
- In case of a single word answer, start the word with an uppercase letter.
|
| 28 |
+
|
| 29 |
+
**Question:** """ +
|
| 30 |
+
question + """
|
| 31 |
+
|
| 32 |
+
**Initial answer:** """ +
|
| 33 |
+
initial_answer + """
|
| 34 |
+
|
| 35 |
**Example 1:** How many 'r' are in strawberry? 3
|
| 36 |
**Example 2:** What is the opposite of white? Black
|
| 37 |
**Example 3:** What is the biggest city in California? Los Angeles
|
| 38 |
**Example 4:** What is the superlative of good? Best
|
| 39 |
**Example 5:** How many states are in the USA? 50
|
| 40 |
+
|
| 41 |
+
**Final answer:**
|
| 42 |
+
|
| 43 |
"""
|
| 44 |
|
| 45 |
client = OpenAI()
|
| 46 |
completion = client.chat.completions.create(
|
| 47 |
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
|
| 48 |
+
model=FINAL_ANSWER_MODEL
|
| 49 |
)
|
| 50 |
|
| 51 |
final_answer = completion.choices[0].message.content
|