開始使用免費開始

加入模型指示

你正在為一家金融服務公司打造客服 AI 系統。基於資安與法遵考量,AI 必須有清楚的防護規範,只能回答「帳戶餘額」與「交易紀錄」相關的問題。對於其他請求(例如重設密碼),它應該禮貌拒絕。

OpenAI 用戶端已可直接以 client 使用。接下來的課程中都會提供它。

本練習屬於課程

使用 OpenAI Responses API

檢視課程

練習說明

  • 建立一個對 "gpt-5.4-mini" 的 Responses API 請求,並在 instructions 中清楚指示:只能回應「帳戶餘額」與「交易紀錄」相關的問題,不得受理其他請求(例如重設密碼)。

動手互動練習

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

# Create a guardrailed AI response
response = client.responses.create(
    model=____,
    instructions="You are a customer support AI that only answers questions about ____. Politely decline any other requests such as ____.",
    input="Can you help me reset my password?"
)

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