Skip to content

Commit db3e27f

Browse files
aahilldeyaaeldeen
andauthored
Apply suggestions from code review
Co-authored-by: Deyaaeldeen Almahallawi <[email protected]>
1 parent 91ec1fc commit db3e27f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 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

@@ -173,6 +174,7 @@ const result = await client.getChatCompletions(deploymentName, messages, { azure
173174
---
174175

175176
Note that:
177+
- `"@azure/openai/types"` is imported which adds Azure-specific definitions (e.g. `data_sources`) to the client types
176178
- The `azureExtensionOptions` property has been replaced with the inner `data_sources` property.
177179
- The `parameters` property has been added to wrap the parameters of the extension, which mirrors the schema of the Azure OpenAI service API.
178180
- Camel case properties have been replaced with snake case properties.
@@ -447,14 +449,16 @@ Note that:
447449
448450
### Content filter
449451
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.
452+
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.
451453
452454
# [OpenAI JavaScript (new)](#tab/javascript-new)
453455
454456
```typescript
457+
import "@azure/openai/types";
458+
455459
const result = await client.chat.completions.create({ model: '', messages });
456460
for (const choice of results.choices) {
457-
const filterResults = (choice as any).content_filter_results;
461+
const filterResults = choice.content_filter_results;
458462
if (!filterResults) {
459463
console.log("No content filter is found");
460464
return;
@@ -486,13 +490,11 @@ for (const choice of results.choices) {
486490
}
487491
```
488492
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-
491493
---
492494
493495
Note that:
494496
- 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 is not part of the `ChatCompletion.Choice` interface, see the [Azure types](#azure-types) section for more information
497+
- `"@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
496498
497499
## Comparing Types
498500
@@ -556,7 +558,7 @@ The following table explores several type names from `@azure/openai` and shows t
556558
557559
## Azure types
558560
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 will be 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.
561+
`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.
560562
561563
## Next steps
562564

0 commit comments

Comments
 (0)