2
【笔记】Python3 操作 ChatGPT
source link: https://loli.fj.cn/2023/07/07/Python3%E6%93%8D%E4%BD%9CChatGPT/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
【笔记】Python3 操作 ChatGPT
2023-07-07
Python3 操作 ChatGPT
- 获取 APIKey
pip3 install openai
操作 ChatGPT
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)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK