GenAI_Chatbot / gpt.py
Ridealist's picture
Init project
2872c06
raw
history blame
1.53 kB
import openai
openai.api_key = "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"
class gpt_api:
@staticmethod
def set_use_model_name(use_model_name):
if not ('global_gpt_model_name' in locals() or 'global_gpt_model_name' in globals()):
global global_gpt_model_name
global_gpt_model_name=use_model_name
#####################################################
# GPT call
#####################################################
@staticmethod
def gpt_call(
system_prompt,
user_prompt
):
if not ('global_gpt_model_name' in locals() or 'global_gpt_model_name' in globals()):
global global_gpt_model_name
# global_gpt_model_name = "gpt-3.5-turbo"
global_gpt_model_name = "gpt-4"
response = openai.ChatCompletion.create(
model=global_gpt_model_name,
messages=[
{
"role": "system",
"content": system_prompt
},
{
"role": "user",
"content": user_prompt
}
],
# temperature=1.5,
# top_p=0.4,
# presence_penalty=1.5,
# frequency_penalty=1.5
)
output_text = response["choices"][0]["message"]["content"]
# print("output_text", output_text)
return output_text