Text-generation not working any solutions? Error: TypeError: openai.complete is not a function

async function generateMealSuggestions(ingredients) {

    const prompt = `Given the ingredients ${ingredients}, suggest some meal recipes.`;

    const completion = await openai.complete({
        engine: 'text-davinci-003', 
        prompt: prompt,
        maxTokens: 200, 
        apiKey: apiKey 
    });

I get TypeError: openai.complete is not a function
I assume this is maybe older so does not work like this anymore. First time trying to integrate AI in a project. Would be great if someone had a solution for me :slight_smile: I assume complete is not used anymore but I am unsure of the steps to fix this I have looked online but have not found anything

Hi and welcome to the Forum!

You are right that multiple elements of your code are outdated / incorrect. Furthermore, the model text-davinci-003 was deprecated in January this year and replaced by gpt-3.5-turbo-instruct.

If you are looking to use a completions model (as opposed to a chat completions model), then you can use the following code to make an API call.

from openai import OpenAI
import os

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


completion = client.completions.create(
    model="gpt-3.5-turbo-instruct",  
    prompt="Replace with your message",
    temperature=0, 
    max_tokens=200
)

print(completion.choices[0].text)
2 Likes

Thank you, if you dont mind I hAve another question, I tried this but then get another error "429 You exceeded your current quota, " but I have not made a successful request yet and it doesnt show any usage in the dashboard. Do you know what could be the problem?

In order to use the API, you need to pre-fund your account with a minimum of USD 5. OpenAI has migrated to prepaid billing as well as no longer grants free credits when you set up your account.

You can add a payment methods and then add credits under settings > billing. Once it shows a positive balance, you can start using the API.

2 Likes

Thank you for the help, do you know how far $5 would go?

It really depends on the amount of input and output tokens.
Here’s the pricing for gpt-3.5-turbo-instruct:

image

Source: https://openai.com/api/pricing/

With OpenAI’s tokenizer tool you can get an idea on the amount tokens for a given input/output:

https://platform.openai.com/tokenizer

3 Likes

Thanks for all your help! If only things were free haha! I tried using othe AI such as hugging face but I couldnt seem to get it to work but this seems very good so I am hoping if I pay the error will go and then I will have no more errors. Hopefully it can help towards my portfolio!

Thanks again! have a great day

2 Likes