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
@@ -64,6 +65,7 @@ If not set, the API version defaults to the last known one before the release of
64
65
On the other hand, the `AzureOpenAI` client is constructed as follows:
65
66
66
67
Migrated code:
68
+
67
69
```typescript
68
70
import { AzureOpenAI } from"openai";
69
71
const deployment ="Your Azure OpenAI deployment";
@@ -91,16 +93,19 @@ The following sections provide examples of how to migrate from `OpenAIClient` an
91
93
The following example shows how to migrate the `getChatCompletions` method call.
92
94
93
95
Original code:
96
+
94
97
```typescript
95
98
const result =awaitclient.getChatCompletions(deploymentName, messages, { maxTokens: 100 });
96
99
```
97
100
98
101
Migrated code:
102
+
99
103
```typescript
100
104
const result =awaitclient.chat.completions.create({ messages, model: '', max_tokens: 100 });
101
105
```
102
106
103
107
Notice the following:
108
+
104
109
- The `getChatCompletions` method has been replaced with the `chat.completions.create` method
105
110
- The `messages` parameter is now passed in the options object with the `messages` property
106
111
- The `maxTokens` property has been renamed to `max_tokens` and the `deploymentName` parameter has been removed. Generally, the names of the properties in the `options` object are the same as in the Azure OpenAI service API, following the snake case convention instead of the camel case convention used in the `AssistantsClient`. This is true for all the properties across all requests and responses in the `AzureOpenAI` client
@@ -111,11 +116,13 @@ Notice the following:
111
116
The following example shows how to migrate the `streamChatCompletions` method call.
@@ -164,7 +173,8 @@ const result = await client.chat.completions.create({
164
173
```
165
174
166
175
Notice that:
167
-
-`"@azure/openai/types"` is imported whcih adds Azure-specific definitions (e.g. `data_sources`) to the client types
176
+
177
+
-`"@azure/openai/types"` is imported which adds Azure-specific definitions (e.g. `data_sources`) to the client types
168
178
- The `azureExtensionOptions` property has been replaced with the inner `data_sources` property
169
179
- The `parameters` property has been added to wrap the parameters of the extension, which mirrors the schema of the Azure OpenAI service API
170
180
- camel case properties have been replaced with snake case properties
@@ -174,6 +184,7 @@ Notice that:
174
184
The following example shows how to migrate the `getAudioTranscription` method call.
175
185
176
186
Original code:
187
+
177
188
```typescript
178
189
import { readFile } from"fs/promises";
179
190
@@ -183,6 +194,7 @@ const result = await client.getAudioTranscription(deploymentName, audio);
183
194
```
184
195
185
196
Migrated code:
197
+
186
198
```typescript
187
199
import { createReadStream } from"fs";
188
200
@@ -193,6 +205,7 @@ const result = await client.audio.transcriptions.create({
193
205
```
194
206
195
207
Notice that:
208
+
196
209
- The `getAudioTranscription` method has been replaced with the `audio.transcriptions.create` method
197
210
- The `AzureOpenAI` has to be constructed with the `deployment` option set to the deployment name in order to use audio operations such as `audio.transcriptions.create`
198
211
- The `model` property is required to be set in the options object but its value is not used in the operation so feel free to set it to any value
@@ -203,6 +216,7 @@ Notice that:
203
216
The following example shows how to migrate the `getAudioTranslation` method call.
204
217
205
218
Original code:
219
+
206
220
```typescript
207
221
import { readFile } from"fs/promises";
208
222
@@ -212,6 +226,7 @@ const result = await client.getAudioTranslation(deploymentName, audio);
212
226
```
213
227
214
228
Migrated code:
229
+
215
230
```typescript
216
231
import { createReadStream } from"fs";
217
232
@@ -222,6 +237,7 @@ const result = await client.audio.translations.create({
222
237
```
223
238
224
239
Notice that:
240
+
225
241
- The `getAudioTranslation` method has been replaced with the `audio.translations.create` method
226
242
- All other changes are the same as in the audio transcription example
227
243
@@ -232,6 +248,7 @@ The following examples show how to migrate some of the `AssistantsClient` method
- The `createMessage` method has been replaced with the `beta.threads.messages.create` method
300
325
- The message specification has been moved from a parameter list to an options object
301
326
@@ -304,6 +329,7 @@ Notice that:
304
329
To run an assistant on a thread, the `createRun` method is used to create a run and then a loop is used to poll the run status until it is in a terminal state. The following example shows how to migrate the run creation and polling.
305
330
306
331
Original code:
332
+
307
333
```typescript
308
334
let runResponse =awaitassistantsClient.createRun(assistantThread.id, {
309
335
assistantId: assistantResponse.id,
@@ -323,6 +349,7 @@ do {
323
349
This code can be migrated and simplified by using the `createAndPoll` method which creates a run and polls it until it is in a terminal state.
- The `createRun` method has been replaced with the `beta.threads.runs.create` and `createAndPoll` methods
338
366
- The `createAndPoll` method is used to create a run and poll it until it is in a terminal state
339
367
@@ -342,6 +370,7 @@ Notice that:
342
370
Without paging, results had to be accessed manually page by page using the `data` property of the response object. For instance, accessing the first page can be done as follows:
343
371
344
372
Original code:
373
+
345
374
```typescript
346
375
for (construnMessageDatumofrunMessages.data) {
347
376
for (constitemof runMessageDatum.content) {
@@ -353,6 +382,7 @@ for (const runMessageDatum of runMessages.data) {
353
382
Pages can be looped through by using the `forawait` loop.
354
383
355
384
Migration code:
385
+
356
386
```typescript
357
387
forawait (construnMessageDatumofrunMessages) {
358
388
for (constitemof runMessageDatum.content) {
@@ -366,16 +396,19 @@ for await (const runMessageDatum of runMessages) {
366
396
The following example shows how to migrate the `getEmbeddings` method call.
- The `getEmbeddings` method has been replaced with the `embeddings.create` method
380
413
- The `input` parameter is now passed in the options object with the `input` property
381
414
- The `deploymentName` parameter has been removed. The `deploymentName` parameter is not needed if the client was created with the `deployment` option. If the client was not created with the `deployment` option, the `model` property in the option object should be set with the deployment name
@@ -385,16 +418,19 @@ Notice that:
385
418
The following example shows how to migrate the `getImages` method call.
386
419
387
420
Original code:
421
+
388
422
```typescript
389
423
constresults=awaitclient.getImages(deploymentName, prompt, { n, size });
390
424
```
391
425
392
426
Migrated code:
427
+
393
428
```typescript
394
429
constresults=awaitclient.images.generate({ prompt, model: '', n, size });
395
430
```
396
431
397
432
Notice that:
433
+
398
434
- The `getImages` method has been replaced with the `images.generate` method
399
435
- The `prompt` parameter is now passed in the options object with the `prompt` property
400
436
- The `deploymentName` parameter has been removed. The `deploymentName` parameter is not needed if the client was created with the `deployment` option. If the client was not created with the `deployment` option, the `model` property in the option object should be set with the deployment name
@@ -404,6 +440,7 @@ Notice that:
404
440
Content filter results is part of the chat completions response types in `OpenAIClient`. The following example shows how to access the content filter results.
@@ -419,9 +456,11 @@ for (const choice of results.choices) {
419
456
...
420
457
}
421
458
```
459
+
422
460
However `AzureOpenAI` does not have a direct equivalent to the `contentFilterResults` property in the `ChatCompletion.Choice` interface. The content filter results can be accessed by importing `"@azure/openai/types"` and accessing the `content_filter_results` property.
423
461
424
462
Migrated code:
463
+
425
464
```typescript
426
465
import"@azure/openai/types";
427
466
@@ -442,8 +481,9 @@ for (const choice of results.choices) {
442
481
```
443
482
444
483
Notice that:
484
+
445
485
- camel case properties have been replaced with snake case properties
446
-
- `"@azure/openai/types"` is imported whcih adds Azure-specific definitions (e.g. `content_filter_results`) to the client types, see the [Azure types](#azure-types) section for more information
486
+
- `"@azure/openai/types"` is imported which adds Azure-specific definitions (e.g. `content_filter_results`) to the client types, see the [Azure types](#azure-types) section for more information
447
487
448
488
## Comparing Types
449
489
@@ -455,10 +495,10 @@ The following table explores several type names from `@azure/openai` and shows t
455
495
| `OpenAIClient` | `AzureOpenAI` | Class | This class replaces the former and has no methods in common with it. See the section on `AzureOpenAI` below. |
456
496
| `AudioResult` | `Transcription`/`Transcription` | Interface | Depending on the calling operation, the two interfaces replace the former one |
457
497
| `AudioResultFormat` | inline union type of the `response_format` property | Alias | It doesn't exist |
458
-
| `AudioResultSimpleJson` | `Transcription`/`Transcription` | Interface | Depending on the calling operation, the two interfaces replace the former one |
459
-
| `AudioResultVerboseJson` | N/A | Interface | |
460
-
| `AudioSegment` | N/A | Interface | |
461
-
| `AudioTranscriptionTask` | N/A | Alias | |
498
+
| `AudioResultSimpleJson` | `Transcription`/`Transcription` | Interface | Depending on the calling operation, the two interfaces replace the former one |
0 commit comments