scrimba
AI Engineering
Intro to Multimodality
GPT-4 with Vision - Part 2
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

GPT-4 with Vision - Part 2
AboutCommentsNotes
GPT-4 with Vision - Part 2
Expand for more info
index.js
run
preview
console
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
dangerouslyAllowBrowser: true,
});

const imgURL = "https://scrimba.com/links/menu-image";

const response = await openai.chat.completions.create({
model: "gpt-4-vision-preview",
messages: [
{
role: "user",
content: [
{ type: "text", text: "Based on this menu, please recommend meal options considering the following: I have a big appetite, am allergic to shellfish, and crave a dessert that's both sweet and tart. I'd like to keep my total spend under $30" },
{
type: "image_url",
image_url: {
url: imgURL
}
}
]
}
]
});
console.log(response.choices[0]);

document.body.innerHTML = `<img src="${imgURL}" alt="Image to analyze">`;
Console
{index:
0
, message:
{role:
"assistant"
, content:
"To satisfy your big appetite while avoiding shellfish and keeping your total spend under $30, here are my recommendations based on the menu: For your main dish, the Chicken Parmesan Sub at $14.99 seems like a hearty choice. It should fill you up without containing any shellfish. And for dessert, the Homemade Key Lime Pie at $8.99 would be a great choice since key lime pie is known for its sweet and tart flavor profile. The total for the Chicken Parmesan Sub and Homemade Key Lime Pie comes to $23.98. This selection will keep you within your budget while also meeting your dietary needs and flavor cravings."
}
, logprobs:
null
, finish_reason:
"stop"
}
,
/index.html
-4:24