GH-3873 Add an api-version
option for Azure OpenAI
#3874
+122
−12
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.
As mentioned in the issue, almost all interfaces of
azure-openai
support theapi-version
option. This is not a parameter within the request body, but rather passed as a query parameter in the URL (refer to the official documentation: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/reference-preview-latest#create-chat-completion). Currently, Spring AI does not support this option. This PR adds that support.What this PR does:
Adds an
apiVersion
configuration option toAzureOpenAiChatOptions
,AzureOpenAiAudioTranscriptionOptions
, andAzureOpenAiEmbeddingOptions
. The parameter is then passed through to the corresponding models and ultimately provided to the Azure SDK. The transmission is achieved via the SDK'sRequestOptions
, which supports appending query parameters to the request URL.I initially intended to add this option to
AzureOpenAiImageOptions
as well. However, the Azure SDK does not expose any method acceptingRequestOptions
as public for image-related operations(com.azure.ai.openai.OpenAIClient#getImageGenerationsWithResponse(java.lang.String, com.azure.core.util.BinaryData, com.azure.core.http.rest.RequestOptions)
). I believe this is a bug, as it is inconsistent with the behavior of other interfaces. I will submit a PR to the Azure SDK to address this. Once that PR is accepted, I will follow up with another PR to Spring AI to add theapiVersion
option toAzureOpenAiImageOptions
.Fixes: #3873