OpenAI Tutorial #2 - Chat Completion

preview_player
Показать описание
In this OpenAI tutorial series you'll learn the basics of how to leverage AI to make small application that generates text and images. In this lesson we'll look at chat completion to replicate a similar behaviour to ChatGPT.

🚀🥷🏼Get early access to this entire course now on Net Ninja Pro:

📂🥷🏼 Access the course files on GitHub:

💻🥷🏼 Modern JavaScript Tutorial:

Рекомендации по теме
Комментарии
Автор

Great tutorial as always. Just a heads up for people facing errors - the syntax has recently changed. Please use the following to test:

const { OpenAI } = require('openai')
require('dotenv').config()

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

const generateAnswer = async () => {
const response = await
messages: [
{ role: 'user', content: 'How many colours does a rainbow have' },
],
model: 'gpt-3.5-turbo',
})


}

generateAnswer()

zainsyed
Автор

8:10 - "max_tokens" - just for my future reference: this applies to the response sent back by API. If you want longer answer, increase it. Max can be around 4000.

EnglishRain
Автор

Can it be imported in the file by using the word import — from “” or it has to be with require?

kikevanegazz
Автор

this does not work at all for me now, maybe they have updated something in the openAi

fridabolin
Автор

chat completion object TypeError: Cannot read properties of undefined (reading 'completions')
at generateMeta i have tried the latest chat completion modules on the documentaion. can you help fix this

fungaifakazi
Автор

Do you have a list of your extensions for vs-code? I do not get IntelliSense on my imported custom module (the OpenAiConfig) and I don't know why...

kooperninja
Автор

i'm getting this problem 'data: {
error: {
message: 'You exceeded your current quota, please check your plan and billing details.',
type: 'insufficient_quota',
param: null,
code: null
}
}' can any one help ?

ZACK-lfgr
Автор

currently building an app with openai API as well but I seem to have an error, Refused to set unsafe header "User-Agent" and a request failed with status code 429. Is there a solution to this?

mosesanthonyfat
Автор

I tried exactly the same code but getting this error

const configuration = new Configuration ({
^

TypeError: Configuration is not a constructor
at Object.<anonymous>
at Module._compile
at Module._extensions..js
at Module.load
at Module._load
at Module.require
at require
at Object.<anonymous>
at Module._compile
at Module._extensions..js

Node.js v18.16.0
can someone help me ?

atefehkasiri
Автор

One off topic question - Why is your channel not verified yet ?

TAMIMMAHMUD
Автор


const configuration=new Configuration({
^

TypeError: Configuration is not a constructor
at Object.<anonymous>
at Module._compile
at Object.Module._extensions..js
at Module.load
at Function.Module._load
at Module.require
at require
at Object.<anonymous>
at Module._compile
at Object.Module._extensions..js

pushpamkumar
Автор

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 code
const generateMeta = async (title) => {
const description = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: `Come up with a description for a YouTube video called ${title}`,
},
],
max_tokens: 100,
});

and here is the error node app

Youtube Video Title:
Complete HTML Tutorial
E:\Erich\Projects\AI
const description = await openai.createChatCompletion({
^

TypeError: openai.createChatCompletion is not a function
at generateMeta (E:\Erich\Projects\AI
at E:\Erich\Projects\AI
at [_onLine] [as _onLine]
at [_line] [as _line]
at [_ttyWrite] [as _ttyWrite]
at ReadStream.onkeypress
at ReadStream.emit (node:events:513:28)
at emitKeys
at emitKeys.next (<anonymous>)
at ReadStream.onData

Any help is appreciated
Cheers

erichgq
Автор

I am facing an error at video 2
i tried github code as well yet output is not same as video output
Please help me for it
I am sharing a drive link where i put error and code images .

chaitanaywaskar