Skip to content
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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

minhanh-phan
Copy link

Description

This sample is intended to show how to use Azure OpenAI On Your Data feature using openai-node library.

Checklist

  • I have read the contribution guidelines
  • I have coordinated with the docs team ([email protected]) if this PR deletes files or changes any file names or file extensions.
  • This notebook or file is added to the CODEOWNERS file, pointing to the author or the author's team.


## Objective

Use openai-node Azure client to generate answers from your data using Azure On Your Data feature.

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,

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"

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.

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.

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!' }],

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?

minhanh-phan and others added 2 commits May 9, 2024 16:00
scenarios/bring-your-own-data/README.md Outdated Show resolved Hide resolved
scenarios/bring-your-own-data/README.md Outdated Show resolved Hide resolved
scenarios/bring-your-own-data/bringYourOwnData.md Outdated Show resolved Hide resolved
scenarios/bring-your-own-data/bringYourOwnData.md Outdated Show resolved Hide resolved
scenarios/bring-your-own-data/bringYourOwnData.md Outdated Show resolved Hide resolved

#### Authenticate using Microsoft Entra ID
```js
const { AzureOpenAI } = require("openai");

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.

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.

scenarios/bring-your-own-data/bringYourOwnData.md Outdated Show resolved Hide resolved
scenarios/bring-your-own-data/bringYourOwnData.md Outdated Show resolved Hide resolved
iseabock pushed a commit to iseabock/azureai-samples that referenced this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants