Completion and completions both attribute not working in openai

response = openai.completions.create(
engine=“text-davinci-002”,
prompt=input_prompt,
**generation_config,
n=1,
stop=[“\n”],
temperature=0.4,
max_tokens=150,
logprobs=10,
safety=safety_settings,
)

when I use I am getting "module ‘openai’ has no attribute ‘completions’ " as well as for ‘Completion’ too.

I’m only familiar with “openai.chat.completions.create()” in the API? If you put a ‘breakpoint()’ before that create call, type in ‘p dir(openai)’ at the python debug prompt to see if there is a ‘completions’ method there.

Try using this code. Also note that text-davinci-002 was deprecated early this year and has been replaced by the gpt-3.5-turbo-instruct model.

from openai import OpenAI
import os

client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY","REPLACE WITH YOUR OPENAI KEY"))


completion = client.completions.create(
    model="gpt-3.5-turbo-instruct",  
    prompt="This is a test.",
    temperature=0, 
    max_tokens=500
)

print(completion.choices[0].text)
1 Like

Echoing what @jr.2509 shared.

The engine param has been deprecated in favour of model and the currently available models to consume with text completion endpoint are:

  • davinci-002
  • babbage-002
  • gpt-3.5-turbo-instruct