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

openai[minor]: Update OpenAI with Azure Specific Code #5323

Merged
merged 13 commits into from May 14, 2024

Conversation

sarangan12
Copy link
Contributor

@sarangan12 sarangan12 commented May 9, 2024

Azure SDK Team has made changes to Open AI Node SDK in PR openai/openai-node#718. In that PR, a new AzureOpenAI Client has been introduced. This enables the OpenAI SDK Users to access Azure Hosted Services with their credentials object instead of OpenAI Key.

This PR is to make changes to @langchain/openai package to make the corresponding changes so Langchain users also could access their Azure Hosted OpenAI service with the credentials object. Required test cases have already been added to the PR.

@achandmsft @deyaaeldeen @xirzec FYI.....

Copy link

vercel bot commented May 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 11:45pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview May 13, 2024 11:45pm

@sarangan12 sarangan12 marked this pull request as ready for review May 9, 2024 06:48
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label May 9, 2024
@sarangan12 sarangan12 changed the title Update OpenAI with Azure Specific Code [Not Ready for review yet] Update OpenAI with Azure Specific Code May 9, 2024
@dosubot dosubot bot added the auto:improvement Medium size change to existing code to handle new use-cases label May 9, 2024
@@ -41,11 +41,12 @@
"dependencies": {
Copy link

Choose a reason for hiding this comment

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

Hey there! 👋 I noticed that the package.json file has an update to the "openai" dependency version and a new dev dependency "@azure/identity" added. This is just a heads up for the maintainers to review the changes in dependencies. Keep up the great work! 🚀

@@ -48,6 +43,56 @@ export class AzureChatOpenAI extends ChatOpenAI {
super(newFields);
Copy link

Choose a reason for hiding this comment

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

Hey there! I've reviewed the code changes and it looks like a new HTTP request setup using the AzureOpenAIClient has been added in the _getClientOptions method. I've flagged this for your review to ensure it aligns with the project's requirements. Let me know if you have any questions or need further clarification.

@@ -0,0 +1,829 @@
import { test, jest, expect } from "@jest/globals";
Copy link

Choose a reason for hiding this comment

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

Hey team, I've reviewed the code and noticed that the changes in this PR access environment variables using the getEnvironmentVariable function. This comment is to flag the change for your review. Let me know if you need any further assistance!

@@ -0,0 +1,333 @@
import { test, expect } from "@jest/globals";
Copy link

Choose a reason for hiding this comment

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

Hey team, just a heads up that I've flagged a change in the PR that uses the getEnvironmentVariable function to access environment variables. It's important for maintainers to review this change to ensure proper handling of environment variables.

@sarangan12 sarangan12 changed the title [Not Ready for review yet] Update OpenAI with Azure Specific Code Update OpenAI with Azure Specific Code May 9, 2024
Copy link
Collaborator

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

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

Why wouldn't you just use the @langchain/azure-openai package?

@bracesproul bracesproul added the question Further information is requested label May 9, 2024
@sarangan12
Copy link
Contributor Author

The @langchain/azure-openai package uses the @azure/openai SDK to access azure. Now, openai package itself has added features to support the same (independent of the @azure/openai package). This PR is to ensure that @langhchain/openai package takes advantage of this new feature provided by openai.

It is possible that similar changes could happen in @langchain/azure-openai package (i.e. make sure it uses openai package instead of @azure/openai package). But, then there will be 2 packages (@langchain/openai and @langchain/azure-openai packages) and both depend/use the same openai package which will be redundant.

@bracesproul
Copy link
Collaborator

The @langchain/azure-openai package uses the @azure/openai SDK to access azure. Now, openai package itself has added features to support the same (independent of the @azure/openai package). This PR is to ensure that @langhchain/openai package takes advantage of this new feature provided by openai.

It is possible that similar changes could happen in @langchain/azure-openai package (i.e. make sure it uses openai package instead of @azure/openai package). But, then there will be 2 packages (@langchain/openai and @langchain/azure-openai packages) and both depend/use the same openai package which will be redundant.

But what are the features that would compel someone to use @langchain/openai to connect to Azure, instead of just using @langchain/azure-openai?

If it's just the ability to have one package installed, and use it to hit the OAI & Azure APIs, I don't think we want that since the packages are small enough already.

@sarangan12
Copy link
Contributor Author

@bracesproul Actually Yes. It is the reasoning that the users could just install one package (@langchain/openai) and get access to both OpenAI and Azure OpenAI and while doing this they could use the credentials (created in Azure) to access it. They do not have to use @langchain/azure-openai package at all.

Now, if you prefer I could make the same change in @langchain/azure-openai package. But, then you will have 2 packages - both using the openai package. What would be your recommendation to such a proposal?

@achandmsft
Copy link

@bracesproul,
We (Microsoft) worked closely with OpenAI (and Stainless) and I also touched upon this strategy briefly with @jacoblee93 from LangChainJS a few weeks ago. Reiterating here:

The goal here is to provide LangChainJS developers using OpenAI with the same quality of experience as LangChain (Python) developers. JavaScript developers want to seamlessly switch between OpenAI and Azure OpenAI endpoints using a single SDK without needing to change packages when talking to different OpenAI endpoints. All LangChain (Python) developers already enjoy this capability today without needing any Azure specific packages across the board: https://python.langchain.com/v0.1/docs/integrations/llms/azure_openai/#deployments.

In order to enable this experience, we first developed an Azure OpenAI client natively in the OpenAI SDK for JavaScript in order to be on par with Python. We just shipped this support a few days ago (https://www.npmjs.com/package/openai).

The problem with the additional azure specific package is not just the size, it's the fact that if there's a new feature in OpenAI that shows up in Azure OpenAI endpoint; they need to wait first for Azure OpenAI SDK for JavaScript to release a new version and then wait for the @langchain/azure-openai package to be updated to use this version. So they need to perform at least an additional package install/upgrade and if breaking, an additional code update. This is cumbersome (and error prone if there are versioning mismatches across these libraries as OpenAI APIs evolve rapidly).

Our solution provides a simple streamlined developer experience around OpenAI for LangChainJS customers. Hope this helps clarify.

Copy link
Collaborator

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

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

Left a few comments. Good start, need to cleanup a couple nits. Thanks for working on this large PR!

Also, CI is failing, if you could resolve those errors that would be great!

libs/langchain-openai/src/azure/embeddings.ts Outdated Show resolved Hide resolved
libs/langchain-openai/src/azure/embeddings.ts Outdated Show resolved Hide resolved
libs/langchain-openai/src/tests/azure/llms.int.test.ts Outdated Show resolved Hide resolved
libs/langchain-openai/src/types.ts Show resolved Hide resolved
@sarangan12
Copy link
Contributor Author

@bracesproul I have addressed the feedback. Could you please take a look at the PR? Thanks

@jacoblee93 jacoblee93 changed the title Update OpenAI with Azure Specific Code openai[minor]: Update OpenAI with Azure Specific Code May 13, 2024
@jacoblee93
Copy link
Collaborator

I think consolidation is good - but what will become of the @azure/openai package then?

@@ -27,15 +29,8 @@ export class AzureOpenAI extends OpenAI {
configuration?: ClientOptions & LegacyOpenAIInput;
}
) {
// assume the base URL does not contain "openai" nor "deployments" prefix
let basePath = fields?.openAIBasePath ?? "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, this is breaking, isn't it?

I don't think this is heavily used yet and there are no examples in our docs, so I'm ok with a change now.

@jacoblee93
Copy link
Collaborator

Thanks! As noted above, it's technically breaking but this code path doesn't seem to be in our docs yet. Let's try to shim things in the future though once it becomes more prominent.

jacoblee93 added a commit that referenced this pull request May 14, 2024
* Update OpenAI with Azure Specific Code

* Export Embeddings

* Add deployment parameters

* Check to fix build issue

* Update libs/langchain-openai/src/azure/embeddings.ts

Co-authored-by: Brace Sproul <[email protected]>

* Update libs/langchain-openai/src/azure/embeddings.ts

Co-authored-by: Brace Sproul <[email protected]>

* nit changes

* Update Test Descriptions

* Format

* Fix types

---------

Co-authored-by: Brace Sproul <[email protected]>
Co-authored-by: jacoblee93 <[email protected]>
jacoblee93 added a commit that referenced this pull request May 14, 2024
* Update OpenAI with Azure Specific Code

* Export Embeddings

* Add deployment parameters

* Check to fix build issue

* Update libs/langchain-openai/src/azure/embeddings.ts



* Update libs/langchain-openai/src/azure/embeddings.ts



* nit changes

* Update Test Descriptions

* Format

* Fix types

---------

Co-authored-by: Sarangan Rajamanickam <[email protected]>
Co-authored-by: Brace Sproul <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases lgtm PRs that are ready to be merged as-is size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants