scrimba
AI Engineering
Intro to AI Engineering
A quick word about models
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

A quick word about models
AboutCommentsNotes
A quick word about models
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 rap genius. When given a topic, create a five-line rap about that topic.'
},
{
role: 'user',
content: 'Television'
}
]

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

console.log(response)

//{id: "chatcmpl-8KkbjF5f6n8WDUBBBBVK3C3AVArSs", object: "chat.completion", created: 1699956411, model: "gpt-4-0613", choices: [{index: 0, message: {role: "assistant", content: "On the screen, visions flicker, intense like a flame, TV got me hypnotized, call it the frame game. Channel surfing like a wave, all day, all night, From reality to fiction, it's my insight. In a world of pixels, my mind takes flight."}, finish_reason: "stop"}], usage: {prompt_tokens: 33, completion_tokens: 58, total_tokens: 91}}
Console
{id:
"chatcmpl-8Ko02LlHXmKsxlG2HEzJDhhVqWbCf"
, object:
"chat.completion"
, created:
1699969450
, model:
"gpt-4-1106-preview"
, choices:
[
{index:
0
, message:
{role:
"assistant"
, content:
"Yo, switchin' channels, on that television quest, Binge-watching series, no time to rest. From drama to comedy, in HD finesse, Reality to fantasy, it's visual finesse. Glued to the screen, yeah, we all obsessed!"
}
, finish_reason:
"stop"
}
]
, usage:
{prompt_tokens:
33
, completion_tokens:
55
, total_tokens:
88
}
, system_fingerprint:
"fp_a24b4d720c"
}
,
/index.html
-5:29