您的第一个 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?
本练习是课程的一部分
使用 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)