Skip to content

fix: forward image detailLevel in Azure OpenAI chat requests - #6220

Open
Lubaoshuai wants to merge 1 commit into
langchain4j:mainfrom
Lubaoshuai:fix/azure-image-detail-level
Open

Lubaoshuai wants to merge 1 commit into
langchain4j:mainfrom
Lubaoshuai:fix/azure-image-detail-level

Conversation

@Lubaoshuai

Copy link
Copy Markdown
Contributor

Issue

Closes #5508

Change

InternalAzureOpenAiHelper.toOpenAiMessage() built ChatMessageImageUrl from the URL only and never called setDetail(...), so the user-specified image detail level was silently dropped and Azure always applied its server default.

This PR maps ImageContent.DetailLevel to the Azure SDK ChatMessageImageDetailLevel and forwards it in the request:

  • LOW / HIGH / AUTO are forwarded as-is.
  • A null detail level is not sent.
  • Unsupported values (MEDIUM, ULTRA_HIGH) now throw UnsupportedFeatureException instead of being silently lost — the same approach the sibling langchain4j-open-ai module uses in OpenAiUtils.toDetail(...).

This also makes the request consistent with AzureOpenAiTokenCountEstimator.estimateImageTokens(), which is already detail-aware (so token estimation and the actual request no longer disagree).

General checklist

  • There are no breaking changes (API, behaviour)
  • I have added unit and/or integration tests for my change
  • The tests cover both positive and negative cases
  • I have manually run all the unit and integration tests in the module I have added/changed, and they are all green (mvn -pl langchain4j-azure-open-ai test: 72 tests, 0 failures)
  • I have manually run all the unit and integration tests in the core and main modules, and they are all green
  • I have added/updated the documentation (no documentation change required — the behavior now matches the documented DetailLevel semantics)
  • I have added an example in the examples repo (only for "big" features)
  • I have added/updated Spring Boot starter(s) (if applicable)

InternalAzureOpenAiHelper.toOpenAiMessage() built ChatMessageImageUrl from
the URL only and never called setDetail(...), so the user-specified image
detail level (LOW/HIGH/AUTO) was silently dropped and Azure always applied
its server default. This also disagreed with AzureOpenAiTokenCountEstimator,
which is detail-aware, and with the langchain4j-open-ai module, which
forwards the detail level.

Mapped ImageContent.DetailLevel to the Azure SDK ChatMessageImageDetailLevel
following the same approach as OpenAiUtils.toDetail(): null stays null and
unsupported values (MEDIUM, ULTRA_HIGH) throw UnsupportedFeatureException
instead of being silently lost.

Fixes langchain4j#5508

This branch has not been deployed

No deployments
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.

[BUG] Azure OpenAI: image detailLevel is ignored and not sent to the API

1 participant