GenAI_Chatbot / gpt.py
Ridealist's picture
Update gpt.py
b69e49a
import openai
import streamlit as st
openai.api_key = st.secrets['OPENAI_API_KEY']
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