Skip to content

fix: support azure-ai-translation-text 1.0.0+ stable SDK#79

Open
octo-patch wants to merge 1 commit intoabus-aikorea:mainfrom
octo-patch:fix/issue-61-azure-translator-credential-import
Open

fix: support azure-ai-translation-text 1.0.0+ stable SDK#79
octo-patch wants to merge 1 commit intoabus-aikorea:mainfrom
octo-patch:fix/issue-61-azure-translator-credential-import

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #61

Problem

azure-ai-translation-text 1.0.0 (stable, released May 2024) removed the TranslatorCredential class that was available in the 1.0.0b1 beta. Users who install the stable version see a startup crash:

ImportError: cannot import name 'TranslatorCredential' from 'azure.ai.translation.text'

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

  • Wrap the TranslatorCredential import in a try/except and fall back to AzureKeyCredential (from azure.core.credentials) when the stable SDK is installed
  • Introduce a _LEGACY_AZURE_SDK flag to select the correct client constructor and API method signatures at runtime
  • Both 1.0.0b1 and 1.0.0+ are now supported without changing requirements.txt

Testing

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.

…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.
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.

ImportError: cannot import name TranslatorCredential

1 participant