-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletion.py
More file actions
22 lines (20 loc) · 890 Bytes
/
completion.py
File metadata and controls
22 lines (20 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class OpenAICompletion:
def __init__(self, system_message, human_message, model, client):
self.client = client
self.model = model
self.system_message = system_message
self.human_message = human_message
def run(self, text):
response = self.client.chat.completions.create(
model=self.model,
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": self.system_message},
{"role": "user", "content": self.human_message.format(input=text)},
]
)
return self._get_question_from_response(response)
def _get_question_from_response(self, response):
output_str = response.choices[0].message.content
_, question = output_str.split(":")
return question.replace("\"", "").replace("}", "").strip()