openai.ChatCompletion is no longer supported in openai>=1.0.0

In the lecture: https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/8/chatbot there is a code >

`def get_completion_from_messages(messages, model=“gpt-3.5-turbo”, temperature=0):

response = openai.ChatCompletion.create(
    model=model,
    messages=messages,
    temperature=temperature, # this is the degree of randomness of the model's output
)
return response.choices[0].message["content"]` 

that doesnt work localy with the recent openai version.

1 Like

In the Introduction chapter they also mention the alternative code to use for 1.0.0, here

client = openai.OpenAI()

def get_completion(prompt, model="gpt-3.5-turbo"):
    messages = [{"role": "user", "content": prompt}]
    response = client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=0
    )
    return response.choices[0].message.content

However, the Chatbot chapter also needs updated to this alternative code approach for 1.0.0.

1 Like

I am unable to run this code locally on my Visual Studio Code

from openai import OpenAI
import os

client = OpenAI(
    api_key="Api KEY"
    )

prompt = "Translate the following English text to French: '{}'"

response = client.completions.create(engine="text-davinci-003",
prompt=prompt.format('Your English text goes here'),
max_tokens=60)

print(response['choices'][0]['text'])