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

[Azure] Introduce AzureOpenAI client #718

Closed
wants to merge 27 commits into from

Conversation

deyaaeldeen
Copy link
Contributor

@deyaaeldeen deyaaeldeen commented Mar 14, 2024

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Add an Azure client similar to Python's.

To-dos:

  • Export it from the package
  • Add support for Azure-specific models
  • Add an example
  • Add tests

Additional context & links

Copy link
Collaborator

@rattrayalex rattrayalex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/lib/azure/azure.ts Outdated Show resolved Hide resolved
@rattrayalex
Copy link
Collaborator

Thank you for putting this up @deyaaeldeen ! We're discussing internally as well.

src/lib/azure/azure.ts Outdated Show resolved Hide resolved
Copy link

@kristapratico kristapratico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :)

src/lib/azure/azure.ts Outdated Show resolved Hide resolved
src/lib/azure/azure.ts Outdated Show resolved Hide resolved
@deyaaeldeen
Copy link
Contributor Author

deyaaeldeen commented Mar 18, 2024

@rattrayalex I need your help in exporting the Azure client. The index.ts module has the definition of the OpenAI client but I think ideally, that definition may need to live in its own module so that index.ts can export both OpenAI and AzureOpenAI. What do you think?

@rattrayalex
Copy link
Collaborator

We'll take a look at that soon @deyaaeldeen. It may have to wait til next week.

@deyaaeldeen
Copy link
Contributor Author

@rattrayalex Thanks for taking a look! I wonder if there is anything that I can clarify or help with to move this forward?

@rattrayalex
Copy link
Collaborator

thanks for the bump, this slipped through the cracks. I've poked internally.

@pstern-sl
Copy link
Collaborator

Hi! I will take a look and test on my side, but in the interim can you elaborate on the change you are proposing regarding the modules design? (for instance, what are the tradeoffs and alternatives?)

Copy link
Collaborator

@rattrayalex rattrayalex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to leave index.ts largely untouched, instead of moving code into openai.ts?

@deyaaeldeen deyaaeldeen marked this pull request as ready for review April 21, 2024 20:53
@deyaaeldeen deyaaeldeen requested a review from a team as a code owner April 21, 2024 20:53
@deyaaeldeen
Copy link
Contributor Author

Is it possible to leave index.ts largely untouched, instead of moving code into openai.ts?

@rattrayalex done. Could you please take another look? hopefully we can merge it ASAP 😊

Copy link
Collaborator

@rattrayalex rattrayalex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the iteration here! I think its moving in a good direction. Just a few comments from a quick skim, but we need to discuss internally a bit on Monday.

Hopefully @RobertCraigie can provide a more thorough review soon.

src/lib/azure/azure.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
apiVersion = Core.readEnv('OPENAI_API_VERSION'),
endpoint,
deployment,
microsoftEntraTokenProvider,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Python client, do we use the term Entra?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobertCraigie
Copy link
Collaborator

Hey we've moved the OpenAI class definition to a separate src/client.ts file so you can properly inherit from it now :)

@deyaaeldeen
Copy link
Contributor Author

@RobertCraigie Awesome! I updated the client in 780ddbb.

@RobertCraigie
Copy link
Collaborator

Unfortunately we just had to revert the client.ts file change because it broke in certain cases: #816

I tried putting the azure exports at the bottom of the index.ts file and that works in some environments but not all :/

what would you think about this being the main import?

import { AzureOpenAI } from 'openai/azure';

Note that we tried a bunch of different ways of structuring the separate index.ts / client.ts files and it does not seem possible to make that change in a compatible fashion so we'll be looking into splitting them up in the next major version.

@RobertCraigie
Copy link
Collaborator

Actually, you could define the azure client class at the bottom of the index.ts file instead, that'll result in the best end user experience

@deyaaeldeen
Copy link
Contributor Author

@RobertCraigie Thanks for the feedback! I updated the PR accordingly.

src/index.ts Outdated
/**
* A function that returns a Microsoft Entra (formerly known as Azure Active Directory) access token, will be invoked on every request.
*/
microsoftEntraTokenProvider?: (() => string) | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not supporting the equivalent azure_ad_token as well like in the Python client an intentional mismatch? (I haven't read all the context)

in other words, would people be suprised they can't set the AZURE_OPENAI_AD_TOKEN environment variable and have it picked up here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deyaaeldeen in addition to Robert's comments, in the Python client I believe we call this azure_ad not microsoft_entra – is that correct? Can we keep the naming consistent and call it Azure Active Directory instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not supporting the equivalent azure_ad_token as well like in the Python client an intentional mismatch?

Yes, I would like our customers to use the token provider first because it takes care of token refreshing. I can add azureAdToken in the future if it turns out to be needed.

Can we keep the naming consistent and call it Azure Active Directory instead?

Ok I made the update in 670165f and we can plan the switch to the Entra name in the next major version.

Copy link
Collaborator

@RobertCraigie RobertCraigie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good to me. We'll also want to update the README.md docs.

Let me know when the docs have been updated & I'll port these changes over to our side before merging.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be ideal for this to be in tests/lib/azure.test.ts, these are good tests though :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it in 670165f.

Copy link
Collaborator

@rattrayalex rattrayalex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience here!

Few things outstanding:

  1. Entra -> AD, as noted elsewhere
  2. Need to update the Azure section of the README (or add one, similar to Python)

@rattrayalex
Copy link
Collaborator

Ah sorry, @deyaaeldeen my mistake – we actually don't need the README updated, we've done that part on our end. Just the Entra -> Azure AD change would be great.

@rattrayalex
Copy link
Collaborator

rattrayalex commented May 5, 2024

This has been moved to #822, which merged, and will be released in #823.

Thank you very much for the contribution and partnership!

@rattrayalex rattrayalex closed this May 5, 2024
corinagum added a commit to microsoft/teams-ai that referenced this pull request May 7, 2024
## Linked issues

closes: #1497  (issue number)

## Details
**BREAKING CHANGE**
* Updated AssistantPlanner to use `@azure/openai-assistants` as the
underlying client. This supports both OpenAI and Azure OpenAI assistants
v1 endpoints.
* Updated math bot to use Azure OpenAI Assistants API by default.

*Note*: Should migrate to official `openai-node` library once azure
support is checked in. Here's the
[PR](openai/openai-node#718

## Attestation Checklist

- [x] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (updating the
doc strings in the code is sufficient)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes

---------

Co-authored-by: Corina <[email protected]>
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.

None yet

7 participants