【笔记】Python3操作ChatGPT

前言

Python3操作ChatGPT

准备工作

  • 获取APIKey

下载依赖

1
pip3 install openai

操作ChatGPT

1
2
3
4
5
6
7
8
import openai

API_KEY = ""
content = "对话内容"
openai.api_key = API_KEY
chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": f"{content}"}])
ai_say = chat_completion.choices[0].message.content
print(content)

完成

参考文献

PYPI——openai