iamshaunjp / openAI-basics

All course files for the OpenAI Basics Tutorial on the Net Ninja YouTube channel and on NetNinja.dev
31 stars 15 forks source link

openai error #2

Open QueM775 opened 1 year ago

QueM775 commented 1 year ago

I have been following the video but i get an error. I thought it was me so i went to git hub and used the code provided I get the same error. I wonder if it is the openai version the video uses 3.2.1and the one I have is 3.3.0.... here is the error node app Youtube Video Title: Complete HTML Tutorial E:\Erich\Projects\AI projects\Projects\Open-AI\controllers\openaiController.js:4 const description = await openai.createChatCompletion({ ^

TypeError: openai.createChatCompletion is not a function at generateMeta (E:\Erich\Projects\AI projects\Projects\Open-AI\controllers\openaiController.js:4:36) at E:\Erich\Projects\AI projects\Projects\Open-AI\app.js:11:51 at [_onLine] [as _onLine] (node:internal/readline/interface:423:7) at [_line] [as _line] (node:internal/readline/interface:886:18) at [_ttyWrite] [as _ttyWrite] (node:internal/readline/interface:1264:22) at ReadStream.onkeypress (node:internal/readline/interface:273:20) at ReadStream.emit (node:events:513:28) at emitKeys (node:internal/readline/utils:357:14) at emitKeys.next () at ReadStream.onData (node:internal/readline/emitKeypressEvents:64:36)

Any help is appreciated Cheers

tripdog commented 11 months ago

I an error as well, and I too copied the code to be sure it wasn't something that I introduced. Console.log ran as expected up to video #2. Once I got up to the second test at the end of video #2 code, TypeError appeared.

TypeError: Configuration is not a constructor at Object. (/Users/tomphillips/Dropbox/A-Projects/Personal Projects/openai-yt/config/openaiConfig.js:4:23)

Yan006Yan commented 9 months ago

@tripdog in my openaiConfig.js I had the same error as you.

my fix was to do it this way

const OpenAI = require("openai"); const openai = new OpenAI({ apiKey: process.env.OPEN_AI_KEY, });

Yan006Yan commented 9 months ago

@QueM775 they change the way they are calling it, this is what i have in my openaiController.js

`

const openai = require('../config/openaiConfig')

const generateMeta = async(title) => {

const description = await openai.chat.completions.create({
    model: "gpt-3.5-turbo",
    messages: [
        {
            "role": 'user', 
            "content": `Come up with a description for YouTube video called ${ title }`
        }
    ],
    max_tokens: 100
})

console.log(description.choices[0].message)

const tags = await openai.chat.completions.create({
    model: "gpt-3.5-turbo",
    messages: [
        {
            "role": 'user', 
            "content": `Come up with 10 keywords for a youtube video called ${ title }`
        }
    ],
    max_tokens: 100
})

console.log(tags.choices[0].message)

}

const generateImage = async (desc) => {

const image = await openai.images.generate({
    prompt: desc,
    n: 1,
    size: '512x512'
})

console.log(image.data[0].url)

}

module.exports = { generateMeta, generateImage } `

GarethCairns commented 1 month ago

@QueM775 they change the way they are calling it, this is what i have in my openaiController.js

**Pasting the code might look awful.

const openai = require('../config/openaiConfig')

const generateMeta = async(title) => {

const description = await openai.chat.completions.create({
    model: "gpt-3.5-turbo",
    messages: [
        {
            "role": 'user', 
            "content": `Come up with a description for YouTube video called ${ title }`
        }
    ],
    max_tokens: 100
})

console.log(description.choices[0].message)

const tags = await openai.chat.completions.create({
    model: "gpt-3.5-turbo",
    messages: [
        {
            "role": 'user', 
            "content": `Come up with 10 keywords for a youtube video called ${ title }`
        }
    ],
    max_tokens: 100
})

console.log(tags.choices[0].message)

}

const generateImage = async (desc) => {

const image = await openai.images.generate({
    prompt: desc,
    n: 1,
    size: '512x512'
})

console.log(image.data[0].url)

}

module.exports = { generateMeta, generateImage }

This worked for me - the libraries are clearly developing quite quickly.