Trying to use gpt-3.5-turbo instead of da-vinci

Hi,

I have been trying to use Open AI APIs for text classification. From the playground, I am only able to get text-davinci-003 for completion but the result from this API are no where close to the chatGPT bot (chat.openai.com website). So I am trying to switch the model to gpt-3.5-turbo in the below code. But I get this error: InvalidRequestError: This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?

Any guidance on how to use gpt-3.5-turbo? Basically, I want to replicate the chatGPT bot through API calls.

response = openai.Completion.create(
  model="text-davinci-003",
  prompt= prompt,
  temperature=0.7,
  max_tokens=400,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
)

Regards,
dbeings

same here would be great to use the turbo model on the completion api.

Yes, sure.

Go to the main OpenAI API reference page:

In your browser search bar, paste this:

Create chat completion

Then read the API does for the chat completion and it’s easy.

It is important to read the docs.

HTH

:slight_smile:

Here’s sample code of my sentiment analysis function.

def sentiment_analysis(text):
    MODEL = "gpt-3.5-turbo"
    response = openai.ChatCompletion.create(
        model = MODEL,
        messages=[
        {"role": "system", "content": "You are performing text analysis."},
        {"role": "user", "content": "YOUR PROMPT GOES HERE: " + text},
        ],
        temperature = 0,    
        max_tokens = 250,
    )
    message = response["choices"][0]["message"]["content"].strip().lower().translate(str.maketrans('', '', string.punctuation))
    sentiment = None
    if "yes" in message:
        sentiment = "1"
    elif "no" in message:
        sentiment = "2"
    else:
        sentiment = "0"
    return sentiment  

This has essentially been my replacement to move over from the engine system, and functions essentially identically.

try to change end point to:

v1/chat/completions

This is the reference link OpenAI API

1 Like

Thanks. There were two issues at my end:

  1. Was using Completion instead of ChatCompletion
  2. ChatCompletion wasnt working for me as I was an earlier version of openai package. Updating it fixed the issues.

Regards,
dbeings

@databeings that worked for me.
Also useful to note that for NodeJS the method is createChatCompletion.

And the parameters of the function have changed as per the api documentation and introduction guide.

Most notably is that it no longer uses prompt but instead messages which have a specific “chat format”.