docs(openai): document ChatOpenAI endpoint resolution precedence - #11638
Open
Mohan Ram (mohanram-dev) wants to merge 1 commit into
Open
Mohan Ram (mohanram-dev) wants to merge 1 commit into
Mohan Ram (mohanram-dev) wants to merge 1 commit into
Conversation
|
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.
Description
Fixes #11635
This PR documents the base URL endpoint resolution order in
@langchain/openaiand adds unit test coverage to ensure parity with the Python counterpart (langchain-openai).In
@langchain/openai,ChatOpenAIresolves its endpoint according to the following precedence:configuration.baseURL(explicit client option)baseUrl(serialized/loaded compatibility field)OPENAI_API_BASEenvironment variable (read by LangChain — takes precedence overOPENAI_BASE_URL)OPENAI_BASE_URLenvironment variable (read by the underlying OpenAI SDK)https://api.openai.com/v1)Because the underlying
openaiSDK reads onlyOPENAI_BASE_URLand ignoresOPENAI_API_BASE, a leftoverOPENAI_API_BASEin the environment can silently override a newly configuredOPENAI_BASE_URL. This PR adds explicit JSDoc documentation and regression test assertions to make this priority explicit and clear for developers.Changes Made
BaseChatOpenAIFields.configurationinlibs/providers/langchain-openai/src/chat_models/base.ts.ChatOpenAIclass JSDoc inlibs/providers/langchain-openai/src/chat_models/index.ts.libs/providers/langchain-openai/src/chat_models/tests/index.test.tsverifyingOPENAI_API_BASEtakes precedence overOPENAI_BASE_URL, andconfiguration.baseURLtakes precedence over environment variables.Validation
pnpm --filter @langchain/core buildpassed.pnpm --filter @langchain/openai buildpassed.pnpm --filter @langchain/openai test src/chat_models/tests/index.test.tspassed (54/54 tests).pnpm format:checkandpnpm lintpassed with 0 errors.