Skip to content

Commit

Permalink
first commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Mar 2, 2023
1 parent 33c2ff5 commit 5c5bdb7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
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
```
13 changes: 13 additions & 0 deletions bot.py
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)

0 comments on commit 5c5bdb7

Please sign in to comment.