基於角色的輸入
使用 input 與 instructions 參數提供字串輸入,已經能滿足多數需求;但有時候,採用「基於角色」的方法會更適合你的應用。
在這裡,你會拿到一個完整的 Responses API 請求。你的任務是把它改成使用基於角色的訊息格式,同時維持提示內容不變。當你開始整合影像輸入時,這樣可以讓你的應用更容易成功。
本練習屬於課程
使用 OpenAI Responses API
練習說明
- 將
input/instruction形式的 Responses 請求,轉換為基於角色的訊息格式。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Convert this request to use role-based messages
response = client.responses.create(
model="gpt-5.4-mini",
instructions="You are a product cataloging expert who provides concise descriptions.",
input="A mustard-yellow colored winter jacket."
)
print(response.output_text)