指定 OpenAI 模型
OpenAI 提供多種模型,適用於不同情境。在這個練習中,你將指定所用的模型,並定義角色來結構化你的 API 請求。
OpenAI 類別已替你從 openai 函式庫匯入。
本練習屬於課程
Working with the OpenAI API
練習說明
- 指定使用
gpt-4o-mini模型。 - 在
messages清單中指派正確的角色。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="")
response = client.chat.completions.create(
# Specify the model
model="____",
messages=[
# Assign the correct role
{"role": "____",
"content": "Announce my new AI Engineer role on LinkedIn."}]
)
print(response.choices[0].message.content)