You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While OpenAI and Azure OpenAI Service rely on a [common Python client library](https://github.com/openai/openai-python), there are small changes you need to make to your code in order to swap back and forth between endpoints. This article walks you through the common changes and differences you'll experience when working across OpenAI and Azure OpenAI.
17
17
18
-
# [OpenAI Python 0.28.1](#tab/python)
19
-
20
-
## Authentication
21
-
22
-
We recommend using environment variables. If you haven't done this before our [Python quickstarts](../quickstart.md) walk you through this configuration.
openai.api_version ="2023-05-15"# subject to change
96
-
```
97
-
98
-
</td>
99
-
</tr>
100
-
</table>
101
-
102
-
## Keyword argument for model
103
-
104
-
OpenAI uses the `model` keyword argument to specify what model to use. Azure OpenAI has the concept of [deployments](create-resource.md?pivots=web-portal#deploy-a-model) and uses the `deployment_id` keyword argument to describe which model deployment to use. Azure OpenAI also supports the use of `engine` interchangeably with `deployment_id`. `deployment_id` corresponds to the custom name you chose for your model during model deployment. By convention in our docs, we often show `deployment_id`'s which match the underlying model name, but if you chose a different deployment name that doesn't match the model name you need to use that name when working with models in Azure OpenAI.
105
-
106
-
For OpenAI `engine` still works in most instances, but it's deprecated and `model` is preferred.
107
-
108
-
<table>
109
-
<tr>
110
-
<td> OpenAI </td> <td> Azure OpenAI </td>
111
-
</tr>
112
-
<tr>
113
-
<td>
114
-
115
-
```python
116
-
completion = openai.Completion.create(
117
-
prompt="<prompt>",
118
-
model="text-davinci-003"
119
-
)
120
-
121
-
chat_completion = openai.ChatCompletion.create(
122
-
messages="<messages>",
123
-
model="gpt-4"
124
-
)
125
-
126
-
embedding = openai.Embedding.create(
127
-
input="<input>",
128
-
model="text-embedding-ada-002"
129
-
)
130
-
131
-
132
-
133
-
134
-
```
135
-
136
-
</td>
137
-
<td>
138
-
139
-
```python
140
-
completion = openai.Completion.create(
141
-
prompt="<prompt>",
142
-
deployment_id="text-davinci-003"# This must match the custom deployment name you chose for your model.
143
-
#engine="text-davinci-003"
144
-
)
145
-
146
-
chat_completion = openai.ChatCompletion.create(
147
-
messages="<messages>",
148
-
deployment_id="gpt-4"# This must match the custom deployment name you chose for your model.
149
-
#engine="gpt-4"
150
-
151
-
)
152
-
153
-
embedding = openai.Embedding.create(
154
-
input="<input>",
155
-
deployment_id="text-embedding-ada-002"# This must match the custom deployment name you chose for your model.
156
-
#engine="text-embedding-ada-002"
157
-
)
158
-
```
159
-
160
-
</td>
161
-
</tr>
162
-
</table>
163
-
164
-
## Azure OpenAI embeddings multiple input support
165
-
166
-
OpenAI currently allows a larger number of array inputs with text-embedding-ada-002. Azure OpenAI currently supports input arrays up to 16 for text-embedding-ada-002 Version 2. Both require the max input token limit per API request to remain under 8191 for this model.
167
-
168
-
<table>
169
-
<tr>
170
-
<td> OpenAI </td> <td> Azure OpenAI </td>
171
-
</tr>
172
-
<tr>
173
-
<td>
174
-
175
-
```python
176
-
inputs = ["A", "B", "C"]
177
-
178
-
embedding = openai.Embedding.create(
179
-
input=inputs,
180
-
model="text-embedding-ada-002"
181
-
)
182
-
183
-
184
-
```
185
-
186
-
</td>
187
-
<td>
188
-
189
-
```python
190
-
inputs = ["A", "B", "C"] #max array size=16
191
-
192
-
embedding = openai.Embedding.create(
193
-
input=inputs,
194
-
deployment_id="text-embedding-ada-002"# This must match the custom deployment name you chose for your model.
195
-
#engine="text-embedding-ada-002"
196
-
)
197
-
```
198
-
199
-
</td>
200
-
</tr>
201
-
</table>
202
-
203
-
# [OpenAI Python 1.x](#tab/python-new)
18
+
This article onlys shows examples with the new OpenAI Python 1.x API library. For information on migrating from `0.28.1` to `1.x` refer to our [migration guide](./migration.md).
0 commit comments