chatgpt==对接API

来到首页

https://platform.openai.com/docs/overview

chatgpt==对接API_第1张图片

quickstart turorial

生成API KEY

https://platform.openai.com/api-keys

chatgpt==对接API_第2张图片

来体验下

setx OPENAI_API_KEY "your-api-key-here"

chatgpt==对接API_第3张图片

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==对接API_第4张图片

绑卡,设置可用额度

chatgpt==对接API_第5张图片

执行代码,成功得到返回值

整个流程就是我们叫CHATGPT解释了个概念和写了首诗

{“角色”:“系统”,“内容”:“你是一个富有诗意的助手,善于用创造性的天赋解释复杂的编程概念。”},
{“角色”:“用户”,“内容”:“写一首诗来解释编程中递归的概念。”}

再问多个问题

chatgpt==对接API_第6张图片

得到回答

你可能感兴趣的:(chatgpt,人工智能)