Update util.py
Browse files
util.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
-
|
4 |
-
from openai import OpenAI
|
5 |
|
6 |
def get_questions(file_path):
|
7 |
df = pd.read_json(file_path, lines=True)
|
@@ -13,28 +12,6 @@ def get_questions(file_path):
|
|
13 |
|
14 |
return result
|
15 |
|
16 |
-
#def get_img_b64(file_path):
|
17 |
-
# with open(file_path, "rb") as file:
|
18 |
-
# return base64.b64encode(file.read()).decode("utf-8")
|
19 |
-
|
20 |
-
#def get_imgs_b64(file_path):
|
21 |
-
# video = cv2.VideoCapture(file_path)
|
22 |
-
|
23 |
-
# result = []
|
24 |
-
|
25 |
-
# while video.isOpened():
|
26 |
-
# success, frame = video.read()
|
27 |
-
|
28 |
-
# if not success:
|
29 |
-
# break
|
30 |
-
|
31 |
-
# _, buffer = cv2.imencode(".png", frame)
|
32 |
-
# result.append(base64.b64encode(buffer).decode("utf-8"))
|
33 |
-
|
34 |
-
# video.release()
|
35 |
-
|
36 |
-
# return result
|
37 |
-
|
38 |
def get_final_answer(model, question, answer):
|
39 |
prompt_template = """
|
40 |
You are an expert question answering assistant. Given a question and an initial answer, your task is to provide the final answer.
|
@@ -62,20 +39,11 @@ def get_final_answer(model, question, answer):
|
|
62 |
|
63 |
"""
|
64 |
|
65 |
-
client =
|
66 |
-
|
67 |
-
completion = client.chat.completions.create(
|
68 |
-
model=model,
|
69 |
-
messages=[{"role": "user", "content": [{"type": "text", "text": prompt_template}]}]
|
70 |
-
)
|
71 |
-
|
72 |
-
#client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
return completion.choices[0].message.content
|
80 |
|
81 |
-
|
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
+
from google import genai
|
|
|
4 |
|
5 |
def get_questions(file_path):
|
6 |
df = pd.read_json(file_path, lines=True)
|
|
|
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.
|
|
|
39 |
|
40 |
"""
|
41 |
|
42 |
+
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
response = client.models.generate_content(
|
45 |
+
model=model,
|
46 |
+
contents=[prompt_template]
|
47 |
+
)
|
|
|
|
|
48 |
|
49 |
+
return response.text
|