fix: support azure-ai-translation-text 1.0.0+ stable SDK#79
Open
octo-patch wants to merge 1 commit intoabus-aikorea:mainfrom
Open
fix: support azure-ai-translation-text 1.0.0+ stable SDK#79octo-patch wants to merge 1 commit intoabus-aikorea:mainfrom
octo-patch wants to merge 1 commit intoabus-aikorea:mainfrom
Conversation
…aikorea#61) TranslatorCredential was removed in the stable 1.0.0 release of azure-ai-translation-text. Add a try/except import that falls back to AzureKeyCredential (azure.core.credentials) when the legacy class is unavailable, and branch on _LEGACY_AZURE_SDK to call the correct constructor and renamed API methods (get_supported_languages, from_language, to_language, body) introduced in 1.0.0.
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.
Fixes #61
Problem
azure-ai-translation-text1.0.0 (stable, released May 2024) removed theTranslatorCredentialclass that was available in the 1.0.0b1 beta. Users who install the stable version see a startup crash:The stable SDK also renamed several API methods:
get_languages()→get_supported_languages()translate(content=..., to=..., from_parameter=...)→translate(body=..., to_language=..., from_language=...)Solution
TranslatorCredentialimport in atry/exceptand fall back toAzureKeyCredential(fromazure.core.credentials) when the stable SDK is installed_LEGACY_AZURE_SDKflag to select the correct client constructor and API method signatures at runtimerequirements.txtTesting
Verified the fix by reviewing the azure-ai-translation-text 1.0.0b1 and 1.0.0 source code to confirm the API differences. The try/except ensures the module imports successfully regardless of which SDK version is installed.