Skip to content

Commit 2b21516

Browse files
authored
Update README to use gpt-3.5-turbo by default (#441)
1 parent 91a63f2 commit 2b21516

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

README.md

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Data libraries like `numpy` and `pandas` are not installed by default due to the
4141

4242
```sh
4343
pip install openai[datalib]
44-
````
44+
```
4545

4646
## Usage
4747

@@ -63,16 +63,16 @@ models = openai.Model.list()
6363
# print the first model's id
6464
print(models.data[0].id)
6565

66-
# create a completion
67-
completion = openai.Completion.create(model="ada", prompt="Hello world")
66+
# create a chat completion
67+
chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
6868

69-
# print the completion
70-
print(completion.choices[0].text)
69+
# print the chat completion
70+
print(chat_completion.choices[0].message.content)
7171
```
7272

73-
7473
### Params
75-
All endpoints have a `.create` method that supports a `request_timeout` param. This param takes a `Union[float, Tuple[float, float]]` and will raise an `openai.error.Timeout` error if the request exceeds that time in seconds (See: https://requests.readthedocs.io/en/latest/user/quickstart/#timeouts).
74+
75+
All endpoints have a `.create` method that supports a `request_timeout` param. This param takes a `Union[float, Tuple[float, float]]` and will raise an `openai.error.Timeout` error if the request exceeds that time in seconds (See: https://requests.readthedocs.io/en/latest/user/quickstart/#timeouts).
7676

7777
### Microsoft Azure Endpoints
7878

@@ -86,24 +86,24 @@ openai.api_key = "..."
8686
openai.api_base = "https://example-endpoint.openai.azure.com"
8787
openai.api_version = "2023-03-15-preview"
8888

89-
# create a completion
90-
completion = openai.Completion.create(deployment_id="deployment-name", prompt="Hello world")
89+
# create a chat completion
90+
chat_completion = openai.ChatCompletion.create(deployment_id="deployment-name", model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
9191

9292
# print the completion
93-
print(completion.choices[0].text)
93+
print(completion.choices[0].message.content)
9494
```
9595

9696
Please note that for the moment, the Microsoft Azure endpoints can only be used for completion, embedding, and fine-tuning operations.
9797
For a detailed example of how to use fine-tuning and other operations using Azure endpoints, please check out the following Jupyter notebooks:
98-
* [Using Azure completions](https://github.com/openai/openai-cookbook/tree/main/examples/azure/completions.ipynb)
99-
* [Using Azure fine-tuning](https://github.com/openai/openai-cookbook/tree/main/examples/azure/finetuning.ipynb)
100-
* [Using Azure embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb)
98+
99+
- [Using Azure completions](https://github.com/openai/openai-cookbook/tree/main/examples/azure/completions.ipynb)
100+
- [Using Azure fine-tuning](https://github.com/openai/openai-cookbook/tree/main/examples/azure/finetuning.ipynb)
101+
- [Using Azure embeddings](https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb)
101102

102103
### Microsoft Azure Active Directory Authentication
103104

104105
In order to use Microsoft Active Directory to authenticate to your Azure endpoint, you need to set the `api_type` to "azure_ad" and pass the acquired credential token to `api_key`. The rest of the parameters need to be set as specified in the previous section.
105106

106-
107107
```python
108108
from azure.identity import DefaultAzureCredential
109109
import openai
@@ -120,6 +120,7 @@ openai.api_version = "2023-03-15-preview"
120120

121121
# ...
122122
```
123+
123124
### Command-line interface
124125

125126
This library additionally provides an `openai` command-line utility
@@ -130,12 +131,12 @@ which makes it easy to interact with the API from your terminal. Run
130131
# list models
131132
openai api models.list
132133

133-
# create a completion
134-
openai api completions.create -m ada -p "Hello world"
135-
136-
# create a chat completion
134+
# create a chat completion (gpt-3.5-turbo, gpt-4, etc.)
137135
openai api chat_completions.create -m gpt-3.5-turbo -g user "Hello world"
138136

137+
# create a completion (text-davinci-003, text-davinci-002, ada, babbage, curie, davinci, etc.)
138+
openai api completions.create -m ada -p "Hello world"
139+
139140
# generate images via DALL·E API
140141
openai api image.create -p "two dogs playing chess, cartoon" -n 1
141142

@@ -147,29 +148,41 @@ openai --proxy=http://proxy.com api models.list
147148

148149
Examples of how to use this Python library to accomplish various tasks can be found in the [OpenAI Cookbook](https://github.com/openai/openai-cookbook/). It contains code examples for:
149150

150-
* Classification using fine-tuning
151-
* Clustering
152-
* Code search
153-
* Customizing embeddings
154-
* Question answering from a corpus of documents
155-
* Recommendations
156-
* Visualization of embeddings
157-
* And more
151+
- Classification using fine-tuning
152+
- Clustering
153+
- Code search
154+
- Customizing embeddings
155+
- Question answering from a corpus of documents
156+
- Recommendations
157+
- Visualization of embeddings
158+
- And more
158159

159160
Prior to July 2022, this OpenAI Python library hosted code examples in its examples folder, but since then all examples have been migrated to the [OpenAI Cookbook](https://github.com/openai/openai-cookbook/).
160161

161-
### Chat
162+
### Chat Completions
162163

163164
Conversational models such as `gpt-3.5-turbo` can be called using the chat completions endpoint.
164165

165166
```python
166167
import openai
167168
openai.api_key = "sk-..." # supply your API key however you choose
168169

169-
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world!"}])
170+
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
170171
print(completion.choices[0].message.content)
171172
```
172173

174+
### Completions
175+
176+
Text models such as `text-davinci-003`, `text-davinci-002` and earlier (`ada`, `babbage`, `curie`, `davinci`, etc.) can be called using the completions endpoint.
177+
178+
```python
179+
import openai
180+
openai.api_key = "sk-..." # supply your API key however you choose
181+
182+
completion = openai.Completion.create(model="text-davinci-003", prompt="Hello world")
183+
print(completion.choices[0].text)
184+
```
185+
173186
### Embeddings
174187

175188
In the OpenAI Python library, an embedding represents a text string as a fixed-length vector of floating point numbers. Embeddings are designed to measure the similarity or relevance between text strings.
@@ -248,6 +261,7 @@ image_resp = openai.Image.create(prompt="two dogs playing chess, oil painting",
248261
```
249262

250263
## Audio transcription (Whisper)
264+
251265
```python
252266
import openai
253267
openai.api_key = "sk-..." # supply your API key however you choose
@@ -264,13 +278,13 @@ Async support is available in the API by prepending `a` to a network-bound metho
264278
import openai
265279
openai.api_key = "sk-..." # supply your API key however you choose
266280

267-
async def create_completion():
268-
completion_resp = await openai.Completion.acreate(prompt="This is a test", model="davinci")
281+
async def create_chat_completion():
282+
chat_completion_resp = await openai.ChatCompletion.acreate(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
269283

270284
```
271285

272286
To make async requests more efficient, you can pass in your own
273-
``aiohttp.ClientSession``, but you must manually close the client session at the end
287+
`aiohttp.ClientSession`, but you must manually close the client session at the end
274288
of your program/event loop:
275289

276290
```python

0 commit comments

Comments
 (0)