Update util.py
Browse files
util.py
CHANGED
|
@@ -2,10 +2,9 @@ import pandas as pd
|
|
| 2 |
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
df = pd.read_json(FILE_PATH, lines=True)
|
| 9 |
result=[]
|
| 10 |
|
| 11 |
for index, row in df.iterrows():
|
|
@@ -13,7 +12,7 @@ def get_questions():
|
|
| 13 |
|
| 14 |
return result
|
| 15 |
|
| 16 |
-
def get_final_answer(model, question,
|
| 17 |
prompt_template = """
|
| 18 |
You are an expert question answering assistant. Given a question and an initial answer, your task is to provide the final answer.
|
| 19 |
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,7 +23,7 @@ def get_final_answer(model, question, initial_answer):
|
|
| 24 |
|
| 25 |
**Question:** """ + question + """
|
| 26 |
|
| 27 |
-
**Initial answer:** """ +
|
| 28 |
|
| 29 |
**Example 1:** How many 'r's are in strawberry? 3
|
| 30 |
**Example 2:** What is the opposite of black? White
|
|
@@ -37,6 +36,7 @@ def get_final_answer(model, question, initial_answer):
|
|
| 37 |
"""
|
| 38 |
|
| 39 |
client = OpenAI()
|
|
|
|
| 40 |
completion = client.chat.completions.create(
|
| 41 |
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
|
| 42 |
model=model
|
|
|
|
| 2 |
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
+
def get_questions(file_path):
|
| 6 |
+
df = pd.read_json(file_path, lines=True)
|
| 7 |
+
|
|
|
|
| 8 |
result=[]
|
| 9 |
|
| 10 |
for index, row in df.iterrows():
|
|
|
|
| 12 |
|
| 13 |
return result
|
| 14 |
|
| 15 |
+
def get_final_answer(model, question, answer):
|
| 16 |
prompt_template = """
|
| 17 |
You are an expert question answering assistant. Given a question and an initial answer, your task is to provide the final answer.
|
| 18 |
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.
|
|
|
|
| 23 |
|
| 24 |
**Question:** """ + question + """
|
| 25 |
|
| 26 |
+
**Initial answer:** """ + answer + """
|
| 27 |
|
| 28 |
**Example 1:** How many 'r's are in strawberry? 3
|
| 29 |
**Example 2:** What is the opposite of black? White
|
|
|
|
| 36 |
"""
|
| 37 |
|
| 38 |
client = OpenAI()
|
| 39 |
+
|
| 40 |
completion = client.chat.completions.create(
|
| 41 |
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
|
| 42 |
model=model
|