-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create JS Samples for Azure On Your Data #85
base: main
Are you sure you want to change the base?
Conversation
|
||
## Objective | ||
|
||
Use openai-node Azure client to generate answers from your data using Azure On Your Data feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just copy the objective section from readme here.
const client = new AzureOpenAI({ | ||
azureADTokenProvider: getBearerTokenProvider(credential, scope), | ||
apiVersion, | ||
endpoint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this now.
```js | ||
OPENAI_API_VERSION="Insert the targeted API version here" | ||
AZURE_OPENAI_ENDPOINT="Insert your endpoint here" | ||
AZURE_OPENAI_API_KEY="Insert your API Key here" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's delete this var and focus on the AAD scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add the Search env vars?
``` | ||
|
||
### Using Azure OpenAI client | ||
We will access Azure Open AI service through `openai-node` library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part needs to discuss more that we need to import both identity and openai and refer to https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md.
const deploymentName = "gpt-4"; | ||
const result = await client.chat.completions.create({ | ||
model: deploymentName, | ||
messages: [{ role: 'user', content: 'Write a poem to celebrate my birthday!' }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be consistent throughout the document with using single quotes or double quotes?
Co-authored-by: Deyaaeldeen Almahallawi <[email protected]>
|
||
#### Authenticate using Microsoft Entra ID | ||
```js | ||
const { AzureOpenAI } = require("openai"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a rule of thumb, use import
instead of require
in all Azure SDK-focused code samples for JS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Back in 2021 we found that import
(ESM) didn't provide good Get Started experience for customers exploring our SDK because ESM wasn't supported well in NodeJS. The basic steps of
- npm init
- npm add @azure/some-sdk
- copy and paste sample code from the SDK README.md into a new js file.
- node path-to-file.js
ESM code didn't work out-of-box. Customer had to do additional work to run the code (either transpiling the ESM code into commonjs, passing experimental switch to NodeJS, or use thrid-party loaders). That was why we decided that the JavaScript samples in README.md should use the CommonJS require
Azure/azure-sdk-for-js#15746.
Now that the JS ecosystem has evolved quite a bit, it is definitely worth to re-visit and check whether ESM is good enough for this scenario. We definitely want to use the modern JS features but at the same time don't want bad customer experience.
Adding deploy button for Agent setup
Description
This sample is intended to show how to use Azure OpenAI On Your Data feature using
openai-node
library.Checklist