-
Notifications
You must be signed in to change notification settings - Fork 8
/
call_llm.py
29 lines (23 loc) · 890 Bytes
/
call_llm.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
import openai
import os
class CallLLM:
def __init__(self):
self.openai_api_key = "sk-replaced_me" # os.environ["OPENAI_API_KEY"]
self.llm_kind = "gpt"
def call_llms(self, system_prompt, prompt):
if self.llm_kind == "gpt":
res = self.call_gpt(system_prompt, prompt)
print("[INFO]Requested OpenAI API")
return res
def call_gpt(self, system_prompt, prompt):
openai.api_key = self.openai_api_key
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt}
],
# temperature=1
)
response = response["choices"][0]["message"]["content"]
return response