Search code examples
pythonjupyter-notebookopenai-apigpt-3

OpenAI GPT-3 API: Why do I get an unexpected response?


I am connecting to the GPT-3 API through a Jupyter Notebook. This is the code:

import openai
import os

# Set up your API key
openai.api_key = os.environ["OPENAI_API_KEY"]

# Choose the API endpoint
model_engine = "davinci"

# Create a prompt
prompt = "Hello, ChatGPT!"

# a temperature of 0.5 returns gibberish
# Generate a response
response = openai.Completion.create(
    engine = model_engine,
    prompt = prompt,
    max_tokens = 1024,
    temperature = 0.5,
    frequency_penalty = 0.5,
    presence_penalty = 0.5
)

# Print the response
print(response.choices[0].text)

Attempting to debug the code led to me playing around with the temperature, frequency_penalty and presence_penalty. I figure I'm doing something wrong if I can't make it work with such a simple prompt.

If you want an example of the unexpected responses I am getting from the simple prompt above, here is the beginning of a few of them:

I’m here to review a product that I was sent for free. This is not a paid advertisement and all opinions are my own. I have been using the new Bamboo Pen & Touch tablet from Wacom for about a month now and I have to say that I am very impressed with this product! The Bamboo is a tablet designed for the everyday user, whether you are an artist or just someone who likes to sketch on the computer. It’s also great for people like me who use their tablets primarily for writing.

ChatGPT is a chat bot powered by Google Assistant. It can handle up to 10,000 messages per month for free and more if you pay for premium services. This bot can be used for customer support, sales and marketing, human resources, and more. In this tutorial, I will show you how to create a chatbot using ChatGPT with PHP. We will use Laravel as a backend framework. If you don’t have an account at ChatGPT yet, sign up here first.

I was expecting a simple "Hi, how can I assist". What's incorrect here?


Solution

  • You are using a very old GPT-3 model (i.e., davinci). The performance of the OpenAI API is model-related. Newer models are more capable.

    • text-davinci-003 <-- use this one
    • text-davinci-002
    • davinci