https://github.com/wzpan/chatgpt-python-example
演示如何使用4行代码调用ChatGPT的官方API
https://github.com/wzpan/chatgpt-python-example
chatgpt chatgpt-api chatgpt-python
Last synced: 8 months ago
JSON representation
演示如何使用4行代码调用ChatGPT的官方API
- Host: GitHub
- URL: https://github.com/wzpan/chatgpt-python-example
- Owner: wzpan
- License: mit
- Created: 2023-03-02T04:13:56.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T09:36:28.000Z (about 2 years ago)
- Last Synced: 2025-03-29T17:05:26.295Z (9 months ago)
- Topics: chatgpt, chatgpt-api, chatgpt-python
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 24
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ChatGPT-python-example
演示如何使用 4 行代码调用 ChatGPT 的官方API。要求 Python 版本 > 3.6 。
## 1. 安装依赖
``` bash
pip3 install openai
```
## 2. 执行demo
``` bash
python3 bot.py
```
## 3. 修改对话内容
修改第 4 行代码里的 `content` 参数即可。例如:
``` py
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", \
messages=[{"role": "user", "content": "请使用 Python 实现一个二分查找算法"}])
```
## 4. 切换模型(可选)
通过修改第 4 行代码里的 `model` 参数即可指定模型。可选的模型详见 [models](https://platform.openai.com/docs/models) 。