Skip to content

Commit d53d9ef

Browse files
authored
Update README.md (#24) (#15)
1 parent 7b0f97e commit d53d9ef

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

README.md

+43-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ pre-defined set of classes for API resources that initialize
66
themselves dynamically from API responses which makes it compatible
77
with a wide range of versions of the OpenAI API.
88

9-
This library additionally provides an `openai` command-line utility
10-
which makes it easy to interact with the API from your terminal. Run
11-
`openai api -h` for usage.
12-
139
## Documentation
1410

15-
See the [OpenAI API docs](https://beta.openai.com/docs/api-reference?lang=python). (During
16-
the beta, you'll need to be signed into your account to see them.)
11+
See the [OpenAI API docs](https://beta.openai.com/docs/api-reference?lang=python).
1712

1813
## Installation
1914

@@ -30,9 +25,50 @@ Install from source with:
3025
python setup.py install
3126
```
3227

28+
## Usage
29+
30+
The library needs to be configured with your account's secret key which is available on the [website](https://beta.openai.com/account/api-keys). Either set it as the `OPENAI_API_KEY` environment variable before using the library:
31+
32+
```bash
33+
export OPENAI_API_KEY='sk-...'
34+
```
35+
36+
Or set `openai.api_key` to its value:
37+
38+
```python
39+
import openai
40+
openai.api_key = "sk-..."
41+
42+
# list engines
43+
engines = openai.Engine.list()
44+
45+
# print the first engine's id
46+
print(engines.data[0].id)
47+
48+
# create a completion
49+
completion = openai.Completion.create(engine="ada", prompt="Hello world")
50+
51+
# print the completion
52+
print(completion.choices[0].text)
53+
```
54+
55+
### Command-line interface
56+
57+
This library additionally provides an `openai` command-line utility
58+
which makes it easy to interact with the API from your terminal. Run
59+
`openai api -h` for usage.
60+
61+
```
62+
# list engines
63+
openai api engines.list
64+
65+
# create a completion
66+
openai api completions.create -e ada -p "Hello world"
67+
```
68+
3369
## Requirements
3470

35-
- Python 2.7+ or Python 3.4+ (PyPy supported)
71+
- Python 3.4+
3672

3773
In general we want to support the versions of Python that our
3874
customers are using, so if you run into issues with any version

0 commit comments

Comments
 (0)