Skip to content

Commit 6f559e7

Browse files
committed
Merge branch 'js-migration' of https://github.com/aahill/azure-docs-pr into js-migration
2 parents 53fbb50 + db3e27f commit 6f559e7

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

articles/ai-services/openai/how-to/migration-javascript.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ const stream = await client.streamChatCompletions(deploymentName, messages, { ma
136136
# [OpenAI JavaScript (new)](#tab/javascript-new)
137137

138138
```typescript
139+
import "@azure/openai/types";
140+
139141
const azureSearchEndpoint = "Your Azure Search resource endpoint";
140142
const azureSearchIndexName = "Your Azure Search index name";
141-
const result = await client.chat.completions.create({ model: '', messages, ... { data_sources: [{
143+
const result = await client.chat.completions.create({ model: '', messages, data_sources: [{
142144
type: "azure_search",
143145
parameters: {
144146
endpoint: azureSearchEndpoint,
@@ -148,7 +150,6 @@ const result = await client.chat.completions.create({ model: '', messages, ... {
148150
}
149151
}
150152
}]
151-
} as Record<string, any>
152153
});
153154
```
154155

@@ -172,7 +173,7 @@ const result = await client.getChatCompletions(deploymentName, messages, { azure
172173

173174
---
174175

175-
176+
- `"@azure/openai/types"` is imported which adds Azure-specific definitions (e.g. `data_sources`) to the client types
176177
- The `azureExtensionOptions` property has been replaced with the inner `data_sources` property.
177178
- The `parameters` property has been added to wrap the parameters of the extension, which mirrors the schema of the Azure OpenAI service API.
178179
- Camel case properties have been replaced with snake case properties.
@@ -447,14 +448,16 @@ const results = await client.getImages(deploymentName, prompt, { n, size });
447448
448449
### Content filter
449450
450-
Content filter results are part of the chat completions response types in `OpenAIClient`. The following example shows how to access the content filter results.
451+
Content filter results are part of the chat completions response types in `OpenAIClient`. 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. The following example shows how to access the content filter results.
451452
452453
# [OpenAI JavaScript (new)](#tab/javascript-new)
453454
454455
```typescript
456+
import "@azure/openai/types";
457+
455458
const result = await client.chat.completions.create({ model: '', messages });
456459
for (const choice of results.choices) {
457-
const filterResults = (choice as any).content_filter_results;
460+
const filterResults = choice.content_filter_results;
458461
if (!filterResults) {
459462
console.log("No content filter is found");
460463
return;
@@ -486,13 +489,11 @@ for (const choice of results.choices) {
486489
}
487490
```
488491
489-
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 casting the `results` object to `any` and accessing the `content_filter_results` property.
490-
491492
---
492493
493494
494495
- camel case properties have been replaced with snake case properties
495-
- A cast to `any` is used to access the `content_filter_results` property because it isn't part of the `ChatCompletion.Choice` interface, see the [Azure types](#azure-types) section for more information
496+
- `"@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
496497
497498
## Comparing Types
498499
@@ -556,7 +557,7 @@ The following table explores several type names from `@azure/openai` and shows t
556557
557558
## Azure types
558559
559-
`AzureOpenAI` connects to the Azure OpenAI service and can call all the operations available in the service. However, the types of the requests and responses are inherited from the `OpenAI` and are not yet updated to reflect the additional features supported exclusively by the Azure OpenAI service. TypeScript users are required to cast to a more permissive type such as `Record<string, any>` to access those features. Examples in [the Migration examples](#migration-examples) section show how to do this.
560+
`AzureOpenAI` connects to the Azure OpenAI service and can call all the operations available in the service. However, the types of the requests and responses are inherited from the `OpenAI` and are not yet updated to reflect the additional features supported exclusively by the Azure OpenAI service. TypeScript users will need to import `"@azure/openai/types"` from `@azure/openai@2.0.0-beta.1` which will merge Azure-specific definitions into existing types. Examples in [the Migration examples](#migration-examples) section show how to do this.
560561
561562
## Next steps
562563

0 commit comments

Comments
 (0)