Failed to retrieve response from model: 'Chat' object has no attribute 'Completion'

What is the updated method for the following (completion appears to have been deprecated):
completion = openai.chat.Completion.create(
engine=“gpt-4-turbo”,
prompt=“What’s the meaning of life?”,
max_tokens=50

For chat completions models, it would look as follows:

completion = client.chat.completions.create(
    model="gpt-4-0125-preview",  
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What’s the meaning of life?"}
        ],
    temperature=0, 
    max_tokens=500
)

print(completion.choices[0].message.content)

If you’d like to use a completions model, then you can use gpt-3.5-turbo instruct as follows:

completion = client.completions.create(
    model="gpt-3.5-turbo-instruct",  
    prompt="What is the meaning of life?",
    temperature=0, 
    max_tokens=500
)

print(completion.choices[0].text)

If in doubt, you can always refer to the API documentation here.

1 Like