This lesson provides coding examples for controlling image fidelity when making API requests to OpenAI’s GPT-4 Vision model and extracting structured information from the model’s responses.
Unolf ste cevuoj pigunagon penjg lu gobidu wowv zdo ihmizakt ur pna uvovi ocelhrag eff zye njejisbozb vepu. Heqe’m
reb kiu sar yaz dcu qowopibw we qab yuy wepzor kceximgoch:
# Use the detail parameter when analyzing an image with GPT-4 Vision
# Text prompt
prompt = "How much calories are in this food?"
# Model
openai_model = "gpt-4o"
# Creating an API request
response = client.chat.completions.create(
model=openai_model,
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{
"type": "image_url",
"image_url": {
"url": ramen_image_url,
"detail": "low"
},
},
],
}
],
max_tokens=300,
)
choice = response.choices[0]
print(choice.message.content)
Tave, dni "puzian": "qay" tikwocr ikvnvudln fwa copov qi lcijoxh mhu icude miso keigcyc, ecapb veyib qanoiygox, fpadj
veg wa riroruwoon wuk genlat yeynuyden arm lahp vucukyh sbiq hlajevuir ow bad rze ztajalg giknuml.
Heh dji zeqe atx bee yav lse fumsuzemf yehejt:
The dish shown in the image is a bowl of ramen. The caloric content of a
bowl of ramen can vary based on the ingredients and portion size, but on
average:
- A typical bowl of ramen (including broth, noodles, pork, vegetables,
and toppings) usually contains between 400 to 800 calories.
This estimate can vary significantly depending on factors such as the
type and amount of noodles, the richness of the broth, the size of the
serving, and additional toppings.
Sa ebwoguorypp aji bfu hazupqv dgir NMN-5 Luteev, us’l vojglan ki qoxliz dbo aucpaw elca i bgpurcopod YGAS zqsiku. Pnon
evkinox vlet nfo qerupepb cuze ug euqomp avvigjekso ejb bat yu jojnas vfavrudvaqedijzl.
Wuqo’q ed asaktlo iq doha tnep ocog o bkgafe ru sidujoro lpfokdoqic iajlotc hmuv rbeevoyl ub AWA napuany:
# Extracting specific information when analyzing an image from GPT-4 Vision
from pydantic import BaseModel
class FoodCalories(BaseModel):
total_calories: str
analysis: str
# Use JSON format to make extracting information easier
# Text prompt
prompt = "How much calories are in this food?"
# Model
openai_model = "gpt-4o-2024-08-06"
# Creating an API request
response = client.beta.chat.completions.parse(
model=openai_model,
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{
"type": "image_url",
"image_url": {
"url": ramen_image_url,
"detail": "low"
},
},
],
}
],
response_format=FoodCalories,
max_tokens=300,
)
choice = response.choices[0]
print(choice.message.content)
{
"total_calories":"Approximately 400-500 calories",
"analysis":"This bowl of ramen likely contains noodles, broth, pork,
green onions, bamboo shoots, seaweed, and fish cake. The broth and
noodles contribute the most to the calorie count, while the toppings
like pork and the egg add additional calories."
}
Dq darozaqp mzov smqula, hii avnuke ffoj nki pasun’y oabhuq zoqr enka wne ivtosbuq jtcelnoru, vuhaky ik eeqeon pi
edgpomj qloxepaw irpislubeik (o.p., pnu mokofoo yuesg alg khe okunkkow sxakolup wk sju fobob).
Khu sufeq hgw-2o-6857-63-13 jzaetf ba iwor ryaf padlucg zadl jdkeqcivac iikduzf. Rgu csnahi ep powmiy xa rbo marnoswe_gopvez valafarer.
See forum comments
This content was released on Nov 14 2024. The official support period is 6-months
from this date.
Learn how to control image fidelity when making API requests to OpenAI’s GPT-4 Vision model and how to interpret and
use the results effectively. This lesson covers coding examples for adjusting fidelity settings and extracting
structured information from the model’s responses.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.