开始使用免费开始使用

基于角色的输入

使用 inputinstructions 参数提供字符串输入让您已经走得很远,但有时,采用"基于角色"的方式会更适合您的应用。

这里为您提供了一份完整的 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)
编辑并运行代码