Add LangChainAzureHook for Azure OpenAI support#70441
Open
ColtenOuO wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
Happy to add the remaining vendors (ex. Bedrock, Vertex) as follow-up PRs if that's a direction the maintainers would like to take. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LangChainHook's docstring already flagged this gap: "Providers with bespoke auth (AWS Bedrock, Google Vertex AI / GenAI, Azure OpenAI, Cohere, HuggingFace) reject these kwargs; per-vendor subclasses can be added later mirroring the pydantic-ai pattern."PydanticAIHookalready has that pattern (PydanticAIAzureHook/PydanticAIBedrockHook/PydanticAIVertexHook, each overriding_get_provider_kwargs) -- this PR adds the first LangChain equivalent.Without it,
LangChainHookalways callsinit_chat_model(model, api_key=..., base_url=...), but Azure OpenAI's LangChain classes (AzureChatOpenAI,AzureOpenAIEmbeddings) don't acceptbase_url-- they needazure_endpointandapi_version. Verified against the reallangchain-openaipackage: those are the actual constructor fields/aliases.Changes
LangChainHook._connection_kwargs:@staticmethod-> instance method, so subclasses can override it (matchesPydanticAIHook's_get_provider_kwargs). No behavior change for the base class.LangChainAzureHook(LangChainHook), overriding_connection_kwargsto mapconn.host->azure_endpointand readapi_versionfromconn.extra.langchain-azureconnection type inprovider.yaml; regeneratedget_provider_info.pyviabreeze release-management prepare-provider-documentation --reapply-templates-only --skip-changelog --skip-readme(not hand-edited).Test plan
host -> azure_endpointmapping,api_versionfrom extra, embedding model uses the same mapping, empty kwargs when no credentials set.test_langchain.pypasses (28 passed).ruff format/ruff check,breeze run mypyclean (mypy caught the staticmethod/instance-method override incompatibility, since fixed).scripts/ci/prek/check_provider_yaml_files.pypasses:LangChainAzureHookregistered correctly, 0 errors.Was generative AI tooling used to co-author this PR?