bstraehle commited on
Commit
c945f59
·
verified ·
1 Parent(s): a6b3a3b

Update util.py

Browse files
Files changed (1) hide show
  1. util.py +30 -1
util.py CHANGED
@@ -9,4 +9,33 @@ def get_questions():
9
  for index, row in df.iterrows():
10
  result.append([row["Level"], row["Question"], row["file_name"], row["Final answer"]])
11
 
12
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  for index, row in df.iterrows():
10
  result.append([row["Level"], row["Question"], row["file_name"], row["Final answer"]])
11
 
12
+ return result
13
+
14
+ def get_final_answer(question, initial_answer):
15
+ prompt_template = """
16
+ You are given a question and an initial answer.
17
+ Your final answer must be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
18
+ 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.
19
+ 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.
20
+ 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.
21
+ **Question:** """ + question + """
22
+ **Initial answer:** """ + initial_answer + """
23
+ **Example:** What is the opposite of white? Black
24
+ **Final answer:**
25
+ """
26
+
27
+ client = OpenAI()
28
+ completion = client.chat.completions.create(
29
+ messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
30
+ model="gpt-4o"
31
+ )
32
+
33
+ final_answer = completion.choices[0].message.content
34
+
35
+ print("###")
36
+ print(question)
37
+ print(initial_answer)
38
+ print(final_answer)
39
+ print("###")
40
+
41
+ return final_answer