API Response method changes from legacy version .28 to latest ver 1.11

My issue is here… I am doing a class and there using OPENAI ver 0.28, but i have install the latest OPENAI ver 1.11

The legacy version i can do this and it works
"response = openai.ChatCompletion.create"

In the new version i had try different methods like the one above and
"response =client.chat.completions.create"

I also added this not sure if its necessary:

from openai import OpenAI
client= OpenAI()

Can anyone tell me what is the new way of doing that line of code ? or point me to the link that explains the new method.

Thanks in Advance

Here is my Python code…

import openai
from openai import OpenAI
client= OpenAI()

with open('test_key.txt', 'r') as f:
    api_key = f.read().strip()
openai.api_key = api_key

def gpt_classify_sentiment(prompt, emotions):
    system_prompt = f"""you are an emotionally intelligent assistant.
    Classify the sentiment of the user's text with ONLY ONE OF THE FOLLOWING EMOTIONS: {emotions}.
    After classifying the text, respond with the emotion ONLY."""
    
    try:
        response =client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": system_prompt},
                {"role": "user", "content": prompt}
            ],
            max_tokens=100,
            temperature=0
        )
        
        r = response['choices'][0]['message']['content']
        if not r:
            r = 'N/A'
        
        return r
    except Exception as e:
        print(f"An error occurred: {e}")
        return None

# Test the function
emotions = 'positive, negative'
prompt = 'AI will help my town.'
result = gpt_classify_sentiment(prompt, emotions)
print(result if result else "No output or an error occurred.")

You are not reading the API key properly. You should load it in your Client, like this (this assumed the key is an ENV vaiable):

client = OpenAI(
# This is the default and can be omitted
api_key=os.environ.get(“OPENAI_API_KEY”),
)

Python package has documentation and examples, check them out: GitHub - openai/openai-python: The official Python library for the OpenAI API

@jayreina where you able to solve it? Having similar issue right now with the same course…