来到首页
https://platform.openai.com/docs/overview
quickstart turorial
生成API KEY
https://platform.openai.com/api-keys
来体验下
setx OPENAI_API_KEY "your-api-key-here"
echo %OPENAI_API_KEY%
编写PYTHON代码
pip install --upgrade openai
from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
{"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
]
)
print(completion.choices[0].message)
报错了
You exceeded your current quota, please check your plan and billing details.
原来想用API还要单独购买
绑卡,设置可用额度
执行代码,成功得到返回值
整个流程就是我们叫CHATGPT解释了个概念和写了首诗
{“角色”:“系统”,“内容”:“你是一个富有诗意的助手,善于用创造性的天赋解释复杂的编程概念。”},
{“角色”:“用户”,“内容”:“写一首诗来解释编程中递归的概念。”}
再问多个问题
得到回答