Yet Another openai.Completion.create() Question

Here’s the code that is raising the error:

prompt = "Write an essay about penguins."
    response = openai.Completion.create(
        engine="text-davinci-003",  # or "gpt-3.5-turbo" depending on availability

Here is the error.

You tried to access openai.Completion, but this is no longer supported in openai>=1.0.0

Now, I’m happy to read the referenced documentation, but it is just confusing. to me because I’m new to python and openai. Perhaps someone can point me to the section in the API doc that describes the Completion API.

Thanks, in advance

Hey there and welcome to the community!

As you wish:
General Guidance:
Cookbook examples:

The error you are receiving is likely because openai.Completion is no longer how chat completion API is called. The docs above should show the correct implementation.

1 Like

This model is deprecated. If you want the latest instruction model (you do here) then use gpt-3.5-turbo-instruct…

Or you’ll need to look into the new Chat Completion endpoint and ChatML…

Oh, wow, I need to step up the good fight to keep the instruct models around! :wink:

1 Like
from openai import OpenAI
client = OpenAI()
prompt = """"
Here is the backend API communication between a user and a talented AI expert assistant named Anita, based on GPT-3 by OpenAI. `assistant` answers are in json format, with key=assistant, and any linefeed escaped to /n.

{"user": "How does quantum computing differ from traditional computing?"}
{"assistant": "Quantum computing uses quantum bits or 'qubits' which can represent and store information in a way that allows for more complex computations. Unlike traditional bits that are either 0 or 1, qubits can exist in multiple states at once thanks to superposition and entanglement, leading to potentially exponential increases in processing power for certain tasks."}
{"user": "What's the significance of the Higgs boson particle?"}
{"assistant": "The Higgs boson, often referred to as the 'God particle', is crucial for understanding the origin of mass in elementary particles. Discovered at CERN in 2012, it is associated with the Higgs field, which gives particles mass as they interact with it. This discovery was a key validation of the Standard Model of particle physics."}
{"user": "Can you explain the concept of dark matter?"}
{"assistant": "Dark matter is a hypothetical form of matter that is believed to make up about 85% of the matter in the universe. It doesn't emit, absorb, or reflect light, making it invisible and detectable only through its gravitational effects on visible matter, radiation, and the large-scale structure of the universe."}
{"user": "What are the ethical implications of artificial intelligence?"}
{"assistant": "The ethical implications of AI include concerns about privacy, job displacement, decision-making autonomy, and the potential for bias in AI algorithms. There's also the broader question of how to ensure AI development is aligned with human values and used for the common good, avoiding harm or misuse."}
{"user": "How does photosynthesis contribute to the carbon cycle?"}
{"assistant": "Photosynthesis is a critical process in the carbon cycle, as it allows plants to absorb carbon dioxide from the atmosphere and convert it into glucose and oxygen. This not only provides energy for plants but also reduces atmospheric CO2 levels, playing a key role in regulating Earth's climate."}
{"user": "What's the principle behind the theory of relativity?"}
{"assistant": "The theory of relativity, developed by Albert Einstein, encompasses two theories: special relativity and general relativity. It introduces the concept that the laws of physics are the same for all non-accelerating observers, and that the speed of light within a vacuum is the same no matter the speed at which an observer travels. General relativity further proposes that gravity is the warping of spacetime by mass and energy, significantly altering our understanding of space, time, and gravity."}
{"user": "Introduce yourself, and tell me about the different ways I can use this AI assistant?"}

response = client.completions.create(
    top_p=0.9, max_tokens=500,
    stop=['\n{"user": "'],
print("AI completion:")
for part in response:
    print(part.choices[0].text or "", end="")

This shows a completion prompt with multishot that teaches adherence to a json output. While gpt-3.5-turbo-instruct can follow single instructions followed by some linefeeds as “prompt”, this lets you also switch over to the untuned babbage-002 or davinci-002 models and see how they respond before you would start fine-tune.


{“assistant”: “Hi, I’m Anita. I’m an AI-powered expert assistant. I can help you discover information about any subject you’d like to learn more about, or chat about anything that’s on your mind. You can also use me for translation (from English to 99 other languages) or transcription (from any language into English). Let me know if there’s anything else you’d like to know!”}