-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerators.py
39 lines (36 loc) · 1.05 KB
/
generators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from openai import OpenAI
client = OpenAI()
class Gpt35Generator:
def __init__(self):
self._system_prompt = f"""
You are an assistant for question-answering tasks.
Use the following pieces of retrieved context to answer the question.
If you don't know the answer, just say that you don't know.
Use three sentences maximum and keep the answer concise.
"""
def _generation_prompt(self, question, context):
return f"""
Question: {question}
Context: {context}
Answer:
"""
def get_completion(self, question, context):
completion_obj = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": f"{self._system_prompt}"
},
{
"role": "user",
"content": f"{self._generation_prompt(question, context)}"
}
],
temperature=0,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return completion_obj.choices[0].message.content