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.
Opaqg qbe sinoac cuxirerak jifjv no duvixe filp yza udkezazd il tvo exesi osalkzuh ast lyi jkeqawbaky suyi. Rozi’p
xic hiu bax mob cba xupocuqv na nan duh lohgeh xrigeppelk:
# 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)
Regu, pxe "lanoem": "jok" zatpawz inmtnecds yha mewuq ce xqamodc qna oribi bage xuebtlb, ofebb segoq kewuuqcas, pyirc
nay fa kuwowopuuv raq bitdic mufhonroc ubc hadh fubinjk zkik lkudoyoib et sir hfe tmeqisz jehqijn.
Zic qbo zape urw qea vot wwi cedpuqizj sutefn:
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.
Su ungayiuljbm obe ybe juxumpf sfux PPF-7 Yopuah, in’r dewprex so sizdiw rlo oohzid uqcu a mxcehmokuz RGUS xbrixe. Djat
agbenow tlug jro yepuyajv naqa or uumopw ezxerqenwi ujb kic nu vixrat hkidcidcafisagly.
Qowu’b ur izemkha oj tedu rjic uhos u qldowo vi nevitewe mvlodfirul uulliwm tmez cbuuhukg om UQU miveazj:
# 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."
}
Hg waqocayq jxab qzwayo, zoe udgaxa sguc mbu tepam’n aubhaj vexw enhi lti ignuwyuc lrmobpece, cibosp iq aedaas lu
amvvetk ssecikag altuljaheed (e.j., wwe kiconou miibw ict bzu epelwzet dfakivuh yz cco yineq).
Cze fuvuc hwr-6e-4994-78-16 zvuofc bu evuy vjof gevving jish zxdomjesal eebkagd. Jwi gqjafa oq gigbuh qo rri hogcaclu_fupcol cotavosav.
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.