Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f56eed6

Browse files
authored
[OpenAI] Edit migration guide (Azure#30512)
Fixes typos and spacing.
1 parent 2637a26 commit f56eed6

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

sdk/openai/openai/MIGRATION.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Authenticating `AzureOpenAI` with an API key is as simple as setting the `AZURE_
5353
`OpenAIClient` and `AssistantsClient` are constructed similarly as follows:
5454

5555
Original code:
56+
5657
```typescript
5758
import { OpenAIClient } from "@azure/openai";
5859
const endpoint = "Your Azure OpenAI resource endpoint";
@@ -64,6 +65,7 @@ If not set, the API version defaults to the last known one before the release of
6465
On the other hand, the `AzureOpenAI` client is constructed as follows:
6566

6667
Migrated code:
68+
6769
```typescript
6870
import { AzureOpenAI } from "openai";
6971
const deployment = "Your Azure OpenAI deployment";
@@ -91,16 +93,19 @@ The following sections provide examples of how to migrate from `OpenAIClient` an
9193
The following example shows how to migrate the `getChatCompletions` method call.
9294

9395
Original code:
96+
9497
```typescript
9598
const result = await client.getChatCompletions(deploymentName, messages, { maxTokens: 100 });
9699
```
97100

98101
Migrated code:
102+
99103
```typescript
100104
const result = await client.chat.completions.create({ messages, model: '', max_tokens: 100 });
101105
```
102106

103107
Notice the following:
108+
104109
- The `getChatCompletions` method has been replaced with the `chat.completions.create` method
105110
- The `messages` parameter is now passed in the options object with the `messages` property
106111
- 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:
111116
The following example shows how to migrate the `streamChatCompletions` method call.
112117

113118
Original code:
119+
114120
```typescript
115121
const stream = await client.streamChatCompletions(deploymentName, messages, { maxTokens: 100 });
116122
```
117123

118124
Migrated code:
125+
119126
```typescript
120127
const stream = await client.chat.completions.create({ model: '', messages, max_tokens: 100, stream: true });
121128
```
@@ -125,6 +132,7 @@ const stream = await client.chat.completions.create({ model: '', messages, max_t
125132
The following example shows how to migrate a `getChatCompletions` method call that enables Azure On Your Data with Azure Search.
126133

127134
Original code:
135+
128136
```typescript
129137
const azureSearchEndpoint = "Your Azure Search resource endpoint";
130138
const azureSearchIndexName = "Your Azure Search index name";
@@ -142,6 +150,7 @@ const result = await client.getChatCompletions(deploymentName, messages, { azure
142150
```
143151

144152
Migrated code:
153+
145154
```typescript
146155
import "@azure/openai/types";
147156

@@ -164,7 +173,8 @@ const result = await client.chat.completions.create({
164173
```
165174

166175
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
168178
- The `azureExtensionOptions` property has been replaced with the inner `data_sources` property
169179
- The `parameters` property has been added to wrap the parameters of the extension, which mirrors the schema of the Azure OpenAI service API
170180
- camel case properties have been replaced with snake case properties
@@ -174,6 +184,7 @@ Notice that:
174184
The following example shows how to migrate the `getAudioTranscription` method call.
175185

176186
Original code:
187+
177188
```typescript
178189
import { readFile } from "fs/promises";
179190

@@ -183,6 +194,7 @@ const result = await client.getAudioTranscription(deploymentName, audio);
183194
```
184195

185196
Migrated code:
197+
186198
```typescript
187199
import { createReadStream } from "fs";
188200

@@ -193,6 +205,7 @@ const result = await client.audio.transcriptions.create({
193205
```
194206

195207
Notice that:
208+
196209
- The `getAudioTranscription` method has been replaced with the `audio.transcriptions.create` method
197210
- 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`
198211
- 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:
203216
The following example shows how to migrate the `getAudioTranslation` method call.
204217

205218
Original code:
219+
206220
```typescript
207221
import { readFile } from "fs/promises";
208222

@@ -212,6 +226,7 @@ const result = await client.getAudioTranslation(deploymentName, audio);
212226
```
213227

214228
Migrated code:
229+
215230
```typescript
216231
import { createReadStream } from "fs";
217232

@@ -222,6 +237,7 @@ const result = await client.audio.translations.create({
222237
```
223238

224239
Notice that:
240+
225241
- The `getAudioTranslation` method has been replaced with the `audio.translations.create` method
226242
- All other changes are the same as in the audio transcription example
227243

@@ -232,6 +248,7 @@ The following examples show how to migrate some of the `AssistantsClient` method
232248
#### Assistant creation
233249

234250
Original code:
251+
235252
```typescript
236253
const options = {
237254
model: azureOpenAIDeployment,
@@ -244,6 +261,7 @@ const assistantResponse = await assistantsClient.createAssistant(options);
244261
```
245262

246263
Migrated code:
264+
247265
```typescript
248266
const options = ...;
249267
const assistantResponse = await assistantsClient.beta.assistants.create(
@@ -252,30 +270,35 @@ const assistantResponse = await assistantsClient.beta.assistants.create(
252270
```
253271

254272
Notice that:
273+
255274
- The `createAssistant` method has been replaced with the `beta.assistants.create` method
256275

257276
#### Thread creation
258277

259278
The following example shows how to migrate the `createThread` method call.
260279

261280
Original code:
281+
262282
```typescript
263283
const assistantThread = await assistantsClient.createThread();
264284
```
265285

266286
Migration code:
287+
267288
```typescript
268289
const assistantThread = await assistantsClient.beta.threads.create();
269290
```
270291

271292
Notice that:
293+
272294
- The `createThread` method has been replaced with the `beta.threads.create` method
273295

274296
#### Message creation
275297

276298
The following example shows how to migrate the `createMessage` method call.
277299

278300
Original code:
301+
279302
```typescript
280303
const threadResponse = await assistantsClient.createMessage(
281304
assistantThread.id,
@@ -285,6 +308,7 @@ const threadResponse = await assistantsClient.createMessage(
285308
```
286309

287310
Migration code:
311+
288312
```typescript
289313
const threadResponse = await assistantsClient.beta.threads.messages.create(
290314
assistantThread.id,
@@ -296,6 +320,7 @@ const threadResponse = await assistantsClient.beta.threads.messages.create(
296320
```
297321

298322
Notice that:
323+
299324
- The `createMessage` method has been replaced with the `beta.threads.messages.create` method
300325
- The message specification has been moved from a parameter list to an options object
301326

@@ -304,6 +329,7 @@ Notice that:
304329
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.
305330

306331
Original code:
332+
307333
```typescript
308334
let runResponse = await assistantsClient.createRun(assistantThread.id, {
309335
assistantId: assistantResponse.id,
@@ -323,6 +349,7 @@ do {
323349
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.
324350
325351
Migration code:
352+
326353
```typescript
327354
const runResponse = await assistantsClient.beta.threads.runs.createAndPoll(
328355
assistantThread.id,
@@ -334,6 +361,7 @@ const runResponse = await assistantsClient.beta.threads.runs.createAndPoll(
334361
```
335362
336363
Notice that:
364+
337365
- The `createRun` method has been replaced with the `beta.threads.runs.create` and `createAndPoll` methods
338366
- The `createAndPoll` method is used to create a run and poll it until it is in a terminal state
339367
@@ -342,6 +370,7 @@ Notice that:
342370
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:
343371
344372
Original code:
373+
345374
```typescript
346375
for (const runMessageDatum of runMessages.data) {
347376
for (const item of runMessageDatum.content) {
@@ -353,6 +382,7 @@ for (const runMessageDatum of runMessages.data) {
353382
Pages can be looped through by using the `for await` loop.
354383
355384
Migration code:
385+
356386
```typescript
357387
for await (const runMessageDatum of runMessages) {
358388
for (const item of runMessageDatum.content) {
@@ -366,16 +396,19 @@ for await (const runMessageDatum of runMessages) {
366396
The following example shows how to migrate the `getEmbeddings` method call.
367397
368398
Original code:
399+
369400
```typescript
370401
const embeddings = await client.getEmbeddings(deploymentName, input);
371402
```
372403
373404
Migrated code:
405+
374406
```typescript
375407
const embeddings = await client.embeddings.create({ input, model: '' });
376408
```
377409
378410
Notice that:
411+
379412
- The `getEmbeddings` method has been replaced with the `embeddings.create` method
380413
- The `input` parameter is now passed in the options object with the `input` property
381414
- 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:
385418
The following example shows how to migrate the `getImages` method call.
386419
387420
Original code:
421+
388422
```typescript
389423
const results = await client.getImages(deploymentName, prompt, { n, size });
390424
```
391425
392426
Migrated code:
427+
393428
```typescript
394429
const results = await client.images.generate({ prompt, model: '', n, size });
395430
```
396431
397432
Notice that:
433+
398434
- The `getImages` method has been replaced with the `images.generate` method
399435
- The `prompt` parameter is now passed in the options object with the `prompt` property
400436
- 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:
404440
Content filter results is part of the chat completions response types in `OpenAIClient`. The following example shows how to access the content filter results.
405441
406442
Original code:
443+
407444
```typescript
408445
const results = await client.getChatCompletions(deploymentName, messages);
409446
for (const choice of results.choices) {
@@ -419,9 +456,11 @@ for (const choice of results.choices) {
419456
...
420457
}
421458
```
459+
422460
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.
423461
424462
Migrated code:
463+
425464
```typescript
426465
import "@azure/openai/types";
427466

@@ -442,8 +481,9 @@ for (const choice of results.choices) {
442481
```
443482
444483
Notice that:
484+
445485
- 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
447487
448488
## Comparing Types
449489
@@ -455,10 +495,10 @@ The following table explores several type names from `@azure/openai` and shows t
455495
| `OpenAIClient` | `AzureOpenAI` | Class | This class replaces the former and has no methods in common with it. See the section on `AzureOpenAI` below. |
456496
| `AudioResult` | `Transcription`/`Transcription` | Interface | Depending on the calling operation, the two interfaces replace the former one |
457497
| `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 |
499+
| `AudioResultVerboseJson` | N/A | Interface | |
500+
| `AudioSegment` | N/A | Interface | |
501+
| `AudioTranscriptionTask` | N/A | Alias | |
462502
| `AzureChatEnhancementConfiguration`, `AzureChatEnhancements`, `AzureChatExtensionConfiguration`, `AzureChatExtensionConfigurationUnion`, `AzureChatExtensionDataSourceResponseCitation`, `AzureChatExtensionsMessageContext`, `AzureChatExtensionType`, `AzureChatGroundingEnhancementConfiguration`, `AzureChatOCREnhancementConfiguration`, `AzureCosmosDBChatExtensionConfiguration`, `AzureCosmosDBFieldMappingOptions`, `AzureExtensionsOptions`, `AzureGroundingEnhancement`, `AzureGroundingEnhancementCoordinatePoint`, `AzureGroundingEnhancementLine`, `AzureGroundingEnhancementLineSpan`, `AzureMachineLearningIndexChatExtensionConfiguration`, `AzureSearchChatExtensionConfiguration`, `AzureSearchIndexFieldMappingOptions`, `AzureSearchQueryType`, `ContentFilterBlocklistIdResult`, `ContentFilterCitedDetectionResult`, `ContentFilterDetectionResult`, `ContentFilterErrorResults`, `ContentFilterResult`, `ContentFilterResultDetailsForPrompt`, `ContentFilterResultsForChoice`, `ContentFilterSeverity`, `ContentFilterResultsForPrompt`, `ContentFilterSuccessResultDetailsForPrompt`, `ContentFilterSuccessResultsForChoice`, `ElasticsearchChatExtensionConfiguration`, `ElasticsearchIndexFieldMappingOptions`, `ElasticsearchQueryType`, `ImageGenerationContentFilterResults`, `ImageGenerationPromptFilterResults`, `OnYourDataAccessTokenAuthenticationOptions`, `OnYourDataApiKeyAuthenticationOptions`, `OnYourDataAuthenticationOptions`, `OnYourDataAuthenticationOptionsUnion`, `OnYourDataConnectionStringAuthenticationOptions`, `OnYourDataDeploymentNameVectorizationSource`, `OnYourDataEncodedApiKeyAuthenticationOptions`, `OnYourDataEndpointVectorizationSource`, `OnYourDataKeyAndKeyIdAuthenticationOptions`, `OnYourDataModelIdVectorizationSource`, `OnYourDataSystemAssignedManagedIdentityAuthenticationOptions`, `OnYourDataUserAssignedManagedIdentityAuthenticationOptions`, `OnYourDataVectorizationSource`, `OnYourDataVectorizationSourceType`, `OnYourDataVectorizationSourceUnion`, `PineconeChatExtensionConfiguration`, `PineconeFieldMappingOptions` | N/A | Interfaces and Aliases | See the Azure types section below |
463503
| `AzureKeyCredential` | N/A | Class | The API key can be provided as a string value |
464504
| `ChatChoice` | `ChatCompletion.Choice` | Interface | |

sdk/openai/openai/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"dist/",
4848
"CHANGELOG.md",
4949
"LICENSE",
50+
"MIGRATION.md",
5051
"README.md"
5152
],
5253
"tshy": {

0 commit comments

Comments
 (0)