import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
# if you are in a public notebook, use this
# import getpass
# openai.api_key = getpass.getpass("OPENAI_API_KEY")
def openai_chat_request(messages, model="gpt-3.5-turbo"):
┊ try:
┊ ┊ completion = openai.ChatCompletion.create(
┊ ┊ ┊ model=model,
┊ ┊ ┊ messages=messages,
┊ ┊ )
┊ ┊ return completion.choices[0].message
┊ except Exception as e:
┊ ┊ print("error in openai_chat_request: " + str(e))
┊ ┊ return None