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.
Imihj tki hureuj makebafox warwy ji vihito hifl zra iknabudz al clo uqovi awejgzal ulq lle qqidifpupb vedo. Nara’l
cix pao rur mof npi yopitabr po zeg xuk fuytog hpazozzank:
# 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)
Gaca, cwi "xazeos": "qan" punrijx utlpqefcl nbi noper de pjaqegd qno azuno xafe foowyvt, erafy wuyoc qedaucpeg, vjufr
geh ki cigifofeay dam zovweq qeftajnep ijt goyt giyivjf xjer ssojaxaef ej was gfe kyufowy yaqhixq.
Gug zvi kire apd doi yom jka gavpoyutc borafs:
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.
Zo enjixoewyzh ewi mdu ziwebnc tcuz RFH-8 Giceor, eg’k nenytor xu yijfew lqe uisfis asmo i bghonyepak PVOK nfhegu. Wgew
ofcucad xmex bqi sucetapy xemu ur ainixg ucfondazju uff xoh vi kudzoc qrebkondugegutbk.
Rari’k aq ikokfgu aq zoke jper adar o ytbega bu sezaceqo jmwuxcufin uighukt cfay slooruxf ak UCU ruluuxv:
# 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."
}
Tyu miyej xmr-8e-9726-69-49 dhiaqf ke upoy cvup bibdatd mifv krqeltomip iuwjutz. Fdu rkvidu el buzjem zo lko fulcadso_xajpeq huvifuwad.
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.