Skip to content

Commit

Permalink
docs(azure): update example and readme to use Entra ID (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
deyaaeldeen authored and stainless-app[bot] committed May 31, 2024
1 parent a70f641 commit 0152859
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,18 @@ To use this library with [Azure OpenAI](https://learn.microsoft.com/en-us/azure/
class instead of the `OpenAI` class.

> [!IMPORTANT]
> The Azure API shape differs from the core API shape which means that the static types for responses / params
> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
> won't always be correct.
```ts
const openai = new AzureOpenAI();
import { AzureOpenAI } from 'openai';
import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';

const credential = new DefaultAzureCredential();
const scope = 'https://cognitiveservices.azure.com/.default';
const azureADTokenProvider = getBearerTokenProvider(credential, scope);

const openai = new AzureOpenAI({ azureADTokenProvider });

const result = await openai.chat.completions.create({
model: 'gpt-4-1106-preview',
Expand Down
11 changes: 8 additions & 3 deletions examples/azure.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#!/usr/bin/env -S npm run tsn -T

import { AzureOpenAI } from 'openai';
import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';

// Corresponds to your Model deployment within your OpenAI resource, e.g. gpt-4-1106-preview
// Navigate to the Azure OpenAI Studio to deploy a model.
const deployment = 'gpt-4-1106-preview';

// Make sure to set both AZURE_OPENAI_ENDPOINT with the endpoint of your Azure resource and AZURE_OPENAI_API_KEY with the API key.
// You can find both information in the Azure Portal.
const openai = new AzureOpenAI();
const credential = new DefaultAzureCredential();
const scope = 'https://cognitiveservices.azure.com/.default';
const azureADTokenProvider = getBearerTokenProvider(credential, scope);

// Make sure to set AZURE_OPENAI_ENDPOINT with the endpoint of your Azure resource.
// You can find it in the Azure Portal.
const openai = new AzureOpenAI({ azureADTokenProvider });

async function main() {
console.log('Non-streaming:');
Expand Down
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"express": "^4.18.2",
"next": "^14.1.1",
"openai": "file:..",
"zod-to-json-schema": "^3.21.4"
"zod-to-json-schema": "^3.21.4",
"@azure/identity": "^4.2.0"
},
"devDependencies": {
"@types/body-parser": "^1.19.3",
Expand Down

0 comments on commit 0152859

Please sign in to comment.