fix(langchain): read AzureOpenAI API version from openai_api_version#1649
Open
Spectual wants to merge 1 commit intolangfuse:mainfrom
Open
fix(langchain): read AzureOpenAI API version from openai_api_version#1649Spectual wants to merge 1 commit intolangfuse:mainfrom
Spectual wants to merge 1 commit intolangfuse:mainfrom
Conversation
`_extract_model_name` for `AzureOpenAI` checks `serialized_kwargs["openai_api_version"]` to decide whether a version is available, then reads the value from `serialized_kwargs["deployment_version"]` (`langfuse/langchain/utils.py:73-74`). LangChain's `AzureOpenAI` doesn't expose a `deployment_version` field — only `openai_api_version` and `deployment_name` — so `deployment_version` is always `None`, the `isinstance(deployment_version, str)` check fails, and the function returns the bare deployment name with no version suffix. Read the value from the same key that gates the branch (`openai_api_version`). Combined with the deduplication logic added in PR langfuse#1203, deployments now produce `<deployment_name>-<api_version>` — matching the documented intent of this code path — while still collapsing if the deployment_name already embeds the version. Add `tests/unit/test_extract_model_name.py` with three regression cases: api_version present, api_version absent, and the dedup path from langfuse#1203.
|
|
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
_extract_model_nameforAzureOpenAIchecksserialized_kwargs[\"openai_api_version\"]to decide whether a version isavailable, then reads the value from
serialized_kwargs[\"deployment_version\"](
langfuse/langchain/utils.py:73-74):LangChain's
AzureOpenAIdoesn't expose adeployment_versionfield — onlyopenai_api_versionanddeployment_name. Sodeployment_versionis alwaysNone, theisinstance(deployment_version, str)check at line 82 fails, andthe function returns the bare deployment name with no version suffix even
when the API version is available.
This makes the version suffix that PR #1203 ("fix(langchain): deployment
version in azure model") was trying to keep deduplicated effectively
unreachable for callers who set
openai_api_versionbut use adeployment_name without an embedded version.
Fix
Read the value from the same key that gates the branch (
openai_api_version).Combined with the dedup logic from #1203, deployments now produce
<deployment_name>-<api_version>while still collapsing if thedeployment_name already embeds the version.
Tests
tests/unit/test_extract_model_name.py(new) covers three regression cases:api_versionpresent →\"my-deployment-2024-02-15-preview\"(was\"my-deployment\"before this fix).api_versionabsent →\"my-deployment\"(unchanged).deployment_namealready contains the version → no duplication(preserves fix(langchain): deployment version in azure model #1203's behavior).
I verified the function-level logic by importing
_extract_model_namedirectly and exercising all three cases against a stubbed
serializeddictthat mirrors what LangChain emits — pre-fix the first case returns
\"my-deployment\", post-fix it returns\"my-deployment-2024-02-15-preview\".The repo's full
uvenv wasn't set up in my sandbox, so CI is the canonicalend-to-end run.
Disclaimer: Experimental PR review
Greptile Summary
This PR fixes a one-line key-name mistake in
_extract_model_nameforAzureOpenAI: the branch gated onopenai_api_versionthen read from the non-existentdeployment_version, so the version suffix was always silently dropped. The fix reads from the same key that guards the branch.langfuse/langchain/utils.py: Changesserialized_kwargs.get(\"deployment_version\")toserialized_kwargs.get(\"openai_api_version\"), making the version lookup consistent with the conditional that gates it.tests/unit/test_extract_model_name.py: Adds three focused regression tests covering: version present → appended, version absent → bare deployment name, and version already embedded in name → no duplication.Confidence Score: 5/5
Safe to merge — the change is a one-line key-name fix with no side effects on other model paths.
The fix correctly aligns the value lookup with the key already used in the conditional guard. The surrounding deduplication logic is untouched, and three targeted regression tests verify the before/after behavior. No other code paths are affected.
No files require special attention.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[_extract_model_name called] --> B{AzureOpenAI in serialized_id?} B -- No --> C[Try other model matchers] B -- Yes --> D{invocation_params has model or model_name?} D -- Yes --> E[Return invocation_params value] D -- No --> F{openai_api_version present in serialized_kwargs?} F -- Yes --> G["deployment_version = openai_api_version value FIXED: was deployment_version key, always None"] F -- No --> H[deployment_version = None] G --> I{deployment_name present?} H --> I I -- No --> J[Return None] I -- Yes --> K[deployment_name = serialized_kwargs value] K --> L{deployment_version is str?} L -- No --> M[Return bare deployment_name] L -- Yes --> N{version already in deployment_name?} N -- Yes --> O[Return deployment_name unchanged] N -- No --> P[Return deployment_name + version suffix]Reviews (1): Last reviewed commit: "fix(langchain): read AzureOpenAI API ver..." | Re-trigger Greptile