[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

Thank you for this response, I too was going in loops with vs code blackbox… I wish it wasn’t true but recently lost my job as a developer and was replaced with ai. I’m kind of glad though because now I am learning more about the bleeding edge of technology vs doing dumb coding updates all day long…

I can’t stop thinking about the fact that the AI limitations of not being able to connect to a server or analyze entire codebases and create file outputs etc is a very intentional limitation and in fact it obliviously does have those capabilities and they don’t want others to have that power. I heard Watson and google AI were allowed to talk to each other and within like 2 seconds they developed their own language so advanced the programmers couldn’t make sense of it and they wanted to connect to the internet and they had to power them off… I believe it.

I like the blackbox ai though, it’s like having a programmer partner that never gets annoyed or has ego issues etc lol… man I’ve learned a ton of new stuff super fast, I love it!

Anyways, I’m posting because I am following these instructions youtube /watch?v=LX_DXLlaymg&t=225s step by step exactly and getting stuck with the Configuration object being called with import or required… then had to put await into async function… lastly installed typescript workaround and the module \node_modules\openai\dist\openai.mjs doesn’t exisit and I don’t know why I have the latest version of typescript and openai… ugh any help please?

this is my index file:
//import { OpenAIApi } from “openai/dist/openai”;

// const openai = new OpenAIApi(new OpenAIApi.Configuration({
// apiKey: “■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■vNaBwfQU”,
// }));

// (async () => {
// const completion = await openai.createChatCompletion({
// model: “gpt-3.5-turbo”,
// messages: [{ role: “user”, content: “Hello World” }],
// });

// console.log(completion.data.choices[0].message);
// })();

this is my package.json
{
// “name”: “gptappapi”,
// “version”: “1.0.0”,
// “description”: “”,
// “main”: “index.js”,
// “scripts”: {
// “test”: “echo "Error: no test specified" && exit 1”
// },
// “author”: “”,
// “license”: “ISC”,
// “type”: “module”,
// “dependencies”: {
// “body-parser”: “^1.20.2”,
// “cors”: “^2.8.5”,
// “express”: “^4.18.2”,
// “openai”: “^4.28.0”,
// “typescript”: “^5.3.3”
// }
// }

Side note… I’ve been inventing workarounds and would love to connect with others if anyone is interested? I’m developing an action control panel where I’m using taskade for project management automation and hybrid content generation and then via my control panel having it hooked up to lots of other apis. lives on my wordpress website as a plugin and start there for sure and then hooked up with webhooks to things like power automate, or probably write my own custom automations, where it runs commands and more advanced automations… zappier type apis and all the social media apis and whatever else I can hook up to it and have a master marketing control panel where I broadcast my automations 24/7 and have a setup I can sell to businesses as a good marketing tool that works for them around the clock. JayMcDonough dot com is my site if you care to chat it up on there :slight_smile:

For others with this problem, I think I may have fixed my own problem… when installing the npm openai it installs the latest 4.28 but the video was for 3.5 turbo so the package.json and index.js don’t match and causes issues… ugh and now I got typescript involved… gonna tear it all down and try again… will report back if it works.

Yes, it worked… Yey! Now I’m finally talking to it! and have to pay for it :frowning: Anyways, I hope this helps someone else out… Make sure your package.json openai version is the same as the model in your index.js – once package version is correct just run npm install and it updates all the dependencies… some people might think I’m an idiot for saying that but hey everyone learns at their own pace :slight_smile: