I have code in my app that creates a certificate. That is is here:
SCRIPT_DIR = Path(__file__).parent.absolute()
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(SCRIPT_DIR, relative_path)
def make_full_pem_cert_path(*certs):
certifi_pem_path = certifi.where()
cert_contents = ""
with open(certifi_pem_path, 'r') as f:
cert_contents += f.read()
for cert in certs:
with open(cert, 'r') as f:
cert_contents += f.read()
# Create file in script directory
full_cert_path = os.path.join(SCRIPT_DIR, 'full_cert.pem')
with open(full_cert_path, 'w') as f:
f.write(cert_contents)
return full_cert_path
# Obtain full path to the certs in script bundle
local_cert_path = resource_path('SherbotAI.cer')
openai_cert_path = resource_path('SSL_certificate.crt')
PEM_PATH = make_full_pem_cert_path(local_cert_path, openai_cert_path)
os.environ['REQUESTS_CA_BUNDLE'] = PEM_PATH
The code I used to send a request to the OpenAI servers is here (and it works):
def getGPTResponse(input_text, gpt_model, stream=False):
response = openai.ChatCompletion.create(
model=gpt_model,
messages=[{
"role": "system",
"content": input_text}],
stream=stream
)
return response['choices'][0]['message']['content']
However, now I use the following code in the latest API release:
def getGPTResponse(input_text, gpt_model, stream=False):
client = OpenAI()
response = client.chat.completions.create(
model=gpt_model,
messages=[{
"role": "system",
"content": input_text}],
stream=False
)
return response.choices[0].message.content
Which causes the certification to fail. What is causing this failure? Please help.