scrimba
AI Engineering
Intro to AI Engineering
Tokens
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Tokens
Expand for more info
index.js
run
preview
console
import OpenAI from 'openai'

const openai = new OpenAI({
dangerouslyAllowBrowser: true
})

const messages = [
{
role: 'system',
content: 'You are a helpful assistant that explains things in language a 10-year-old can understand. Your answers are always less than 100 words.'
},
{
role: 'user',
content: 'What is Quantum Computing?'
}
]

const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: messages
})

console.log(response)

//{id: "chatcmpl-8HqFaX41jZKaoQoATAUyoQ5X2kK8R", object: "chat.completion", created: 1699263118, model: "gpt-4-0613", choices: [{index: 0, message: {role: "assistant", content: "Quantum computing is a special kind of computing. Imagine if you could open all your gifts at Christmas at the same time, instead of one after the other. Quantum computers work like that, problem-solving all at once instead of step-by-step. They're really powerful and fast."}, finish_reason: "stop"}], usage: {prompt_tokens: 44, completion_tokens: 56, total_tokens: 100}}
Console
{id:
"chatcmpl-8HqFaX41jZKaoQoATAUyoQ5X2kK8R"
, object:
"chat.completion"
, created:
1699263118
, model:
"gpt-4-0613"
, choices:
[
{index:
0
, message:
{role:
"assistant"
, content:
"Quantum computing is a special kind of computing. Imagine if you could open all your gifts at Christmas at the same time, instead of one after the other. Quantum computers work like that, problem-solving all at once instead of step-by-step. They're really powerful and fast."
}
, finish_reason:
"stop"
}
]
, usage:
{prompt_tokens:
44
, completion_tokens:
56
, total_tokens:
100
}
}
,
/index.html
-5:41