你的第一個 OpenAI API 請求!
為了先預覽接下來要做的事,這裡已經準備好用來向 OpenAI API 發送請求的 Python 程式碼。
把任何問題或指示傳入 content 參數,就能看看 OpenAI 的模型如何回應!
如果一時沒有靈感,可以試試以下提示:
- Why is learning the OpenAI API valuable for developers?
- Suggest three tasks I could automate with the OpenAI API in my job.
- In two sentences, how can the OpenAI API be used to upskill myself?
本練習屬於課程
Working with the OpenAI API
練習說明
- 將
INSERT YOUR PROMPT HERE替換為你的提示,動手嘗試,準備好後送出你的答案!
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
response = client.chat.completions.create(
model="gpt-4o-mini",
max_completion_tokens=100,
# Enter your prompt
messages=[{"role": "user", "content": "INSERT YOUR PROMPT HERE"}]
)
print(response.choices[0].message.content)