-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# ChatGPT-python-example | ||
演示如何使用5行代码调用ChatGPT的官方API | ||
|
||
演示如何使用 5 行代码调用 ChatGPT 的官方API。要求 Python 版本 > 3.6 。 | ||
|
||
## 1. 安装依赖 | ||
|
||
``` bash | ||
pip3 install openai | ||
``` | ||
|
||
## 2. 执行demo | ||
|
||
``` bash | ||
python3 bot.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import openai | ||
openai.api_key = "sk-XXXXXXXXXX" # 你的 OpenAI API Key | ||
|
||
# list models | ||
models = openai.Model.list() | ||
|
||
# create a completion | ||
completion = openai.Completion.create(model="gpt-3.5-turbo", \ | ||
messages=[{"role": "user", "content": "What is the OpenAI mission?"}], \ | ||
api_base="https://api.openai.com/v1/chat") | ||
|
||
# print the completion | ||
print(completion.choices[0].message.content) |