開始使用免費開始

使用 URL 影像進行提示

你正在為一個線上市集建立自動化商品編目系統。系統需要分析商品圖片,並為型錄產生精準的描述。你會使用基於角色的訊息,將影像 URL 傳給模型,並同時要求分類與描述。

一個指向冬季外套照片的 URL 字串已儲存在 image_url,而 visualize_image() 函式也已為你定義好,方便你將圖片與產生的描述進行比對。

本練習屬於課程

使用 OpenAI Responses API

檢視課程

練習說明

  • 新增一則使用者訊息,內容同時包含文字提示(請求對商品進行分類並撰寫描述)以及影像 URL(image_url),並使用正確的內容型別。
  • 使用你的 messages 清單建立對 "gpt-5.4-mini" 模型的請求,並擷取輸出文字。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

messages = [{"role": "system", "content": "You are a product cataloging expert who provides concise classifications and descriptions."}]

# Add user message with text and image
messages.append({
    "role": "____",
    "content": [
        {"type": "____", "____": "Classify this product and write a brief but punchy description for our catalog."},
        {"type": "____", "image_url": "____"}
    ]
})

# Create the response
response = ____

print(response.output_text)
visualize_image(image_url)
編輯並執行程式碼