[SOLVED] Openai.complete not found

Hi, I’m adding a openai function to an existing project. I’m using VSC, yarn, python, node.js. I’ve imported openai to the project and I can see it in my dependencies. Just to test I’ve added a user prompt which should then call openai and display the response.

I’m using import * as openai from ‘openai’
but it cannot find openai.complete in the below code (it’s not a code issue but just for example)

const handleSubmit = async (event) => {
event.preventDefault()

const response = await openai.complete({
  engine: 'davinci',
  prompt: question,
  maxTokens: 150,
  n: 1,
  stop: '\n',
  temperature: 0.7,
})
setAnswer(response.data.choices[0].text) 

}

VSC throws the error:

Property ‘complete’ does not exist on type ‘typeof import(“REDACTED/node_modules/openai/dist/index”)’

ChatGPT unhelpfully advices me to upgrade to the latest version of openai, but I already am. Scratching my head now, although I’m sure it’s something to do with my environment, I just dont know where to look.

Where did you get the code above, is it from ChatGPT?

:slight_smile:

Yeah, chatGPT has been helping me out.

That’s the problem, mate.

Go to the OpenAI API docs and use the examples there and you will not waste so much time with deprecated, buggy , ChatGPT nonsense code .

The OpenAI API docs are much better than ChatGPT :slight_smile:

Hope the helps.

:slight_smile:

1 Like

Thank you, I’ll do that then :smile:

1 Like

5 minutes later - IT WORKS! When chatGPT came out I thought that would be the end of RTFM… guess I was wrong. Thank you.

1 Like

You are welcome.

You have no idea @matthew.rogers how much time we “experienced coders” waste here answering ChatGPT coded nonsense questions.

It’s the “new form of spam” where folks to go ChatGPT, a language generating tool and waste so much time debugging “ChatGPT nonsense” when they could go to the expertly written and up-to-data API docs and have working code, as you just discovered @matthew.rogers

ChatGPT is “OK” for writing draft code which is not based on changing, updating libraries, For example, if you ask ChatGPT to write a method to sort an array of hashes based on a hash key in Python, Ruby, JS, etc. you will probably get a good draft of a code method. That is because that code is “mature” and not based on a lib which changes.

In this case, ChatGPT is working with deprecated code data samples from mid 2021 and so it’s writing depreciated, unusable code for you.

Now you know, @matthew.rogers

Generative AI is NOT going to put experienced developers out of work anytime soon :slight_smile:

Hope this helps!

:slight_smile:

1 Like