|
16 | 16 | SpeechSynthesizer,
|
17 | 17 | )
|
18 | 18 | from azure.core.exceptions import ResourceNotFoundError
|
19 |
| -from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider |
| 19 | +from azure.identity.aio import ( |
| 20 | + AzureDeveloperCliCredential, |
| 21 | + ManagedIdentityCredential, |
| 22 | + get_bearer_token_provider, |
| 23 | +) |
20 | 24 | from azure.monitor.opentelemetry import configure_azure_monitor
|
21 | 25 | from azure.search.documents.aio import SearchClient
|
22 | 26 | from azure.search.documents.indexes.aio import SearchIndexClient
|
|
59 | 63 | CONFIG_CREDENTIAL,
|
60 | 64 | CONFIG_GPT4V_DEPLOYED,
|
61 | 65 | CONFIG_INGESTER,
|
| 66 | + CONFIG_LANGUAGE_PICKER_ENABLED, |
62 | 67 | CONFIG_OPENAI_CLIENT,
|
63 | 68 | CONFIG_SEARCH_CLIENT,
|
64 | 69 | CONFIG_SEMANTIC_RANKER_DEPLOYED,
|
@@ -267,6 +272,7 @@ def config():
|
267 | 272 | "showSemanticRankerOption": current_app.config[CONFIG_SEMANTIC_RANKER_DEPLOYED],
|
268 | 273 | "showVectorOption": current_app.config[CONFIG_VECTOR_SEARCH_ENABLED],
|
269 | 274 | "showUserUpload": current_app.config[CONFIG_USER_UPLOAD_ENABLED],
|
| 275 | + "showLanguagePicker": current_app.config[CONFIG_LANGUAGE_PICKER_ENABLED], |
270 | 276 | "showSpeechInput": current_app.config[CONFIG_SPEECH_INPUT_ENABLED],
|
271 | 277 | "showSpeechOutputBrowser": current_app.config[CONFIG_SPEECH_OUTPUT_BROWSER_ENABLED],
|
272 | 278 | "showSpeechOutputAzure": current_app.config[CONFIG_SPEECH_OUTPUT_AZURE_ENABLED],
|
@@ -429,15 +435,26 @@ async def setup_clients():
|
429 | 435 |
|
430 | 436 | USE_GPT4V = os.getenv("USE_GPT4V", "").lower() == "true"
|
431 | 437 | USE_USER_UPLOAD = os.getenv("USE_USER_UPLOAD", "").lower() == "true"
|
| 438 | + ENABLE_LANGUAGE_PICKER = os.getenv("ENABLE_LANGUAGE_PICKER", "").lower() == "true" |
432 | 439 | USE_SPEECH_INPUT_BROWSER = os.getenv("USE_SPEECH_INPUT_BROWSER", "").lower() == "true"
|
433 | 440 | USE_SPEECH_OUTPUT_BROWSER = os.getenv("USE_SPEECH_OUTPUT_BROWSER", "").lower() == "true"
|
434 | 441 | USE_SPEECH_OUTPUT_AZURE = os.getenv("USE_SPEECH_OUTPUT_AZURE", "").lower() == "true"
|
435 | 442 |
|
436 |
| - # Use the current user identity to authenticate with Azure OpenAI, AI Search and Blob Storage (no secrets needed, |
437 |
| - # just use 'az login' locally, and managed identity when deployed on Azure). If you need to use keys, use separate AzureKeyCredential instances with the |
438 |
| - # keys for each service |
439 |
| - # If you encounter a blocking error during a DefaultAzureCredential resolution, you can exclude the problematic credential by using a parameter (ex. exclude_shared_token_cache_credential=True) |
440 |
| - azure_credential = DefaultAzureCredential(exclude_shared_token_cache_credential=True) |
| 443 | + # Use the current user identity for keyless authentication to Azure services. |
| 444 | + # This assumes you use 'azd auth login' locally, and managed identity when deployed on Azure. |
| 445 | + # The managed identity is setup in the infra/ folder. |
| 446 | + azure_credential: Union[AzureDeveloperCliCredential, ManagedIdentityCredential] |
| 447 | + if os.getenv("WEBSITE_HOSTNAME"): # Environment variable set on Azure Web Apps |
| 448 | + current_app.logger.info("Setting up Azure credential using ManagedIdentityCredential") |
| 449 | + azure_credential = ManagedIdentityCredential() |
| 450 | + elif AZURE_TENANT_ID: |
| 451 | + current_app.logger.info( |
| 452 | + "Setting up Azure credential using AzureDeveloperCliCredential with tenant_id %s", AZURE_TENANT_ID |
| 453 | + ) |
| 454 | + azure_credential = AzureDeveloperCliCredential(tenant_id=AZURE_TENANT_ID, process_timeout=60) |
| 455 | + else: |
| 456 | + current_app.logger.info("Setting up Azure credential using AzureDeveloperCliCredential for home tenant") |
| 457 | + azure_credential = AzureDeveloperCliCredential(process_timeout=60) |
441 | 458 |
|
442 | 459 | # Set up clients for AI Search and Storage
|
443 | 460 | search_client = SearchClient(
|
@@ -576,6 +593,7 @@ async def setup_clients():
|
576 | 593 | current_app.config[CONFIG_SEMANTIC_RANKER_DEPLOYED] = AZURE_SEARCH_SEMANTIC_RANKER != "disabled"
|
577 | 594 | current_app.config[CONFIG_VECTOR_SEARCH_ENABLED] = os.getenv("USE_VECTORS", "").lower() != "false"
|
578 | 595 | current_app.config[CONFIG_USER_UPLOAD_ENABLED] = bool(USE_USER_UPLOAD)
|
| 596 | + current_app.config[CONFIG_LANGUAGE_PICKER_ENABLED] = ENABLE_LANGUAGE_PICKER |
579 | 597 | current_app.config[CONFIG_SPEECH_INPUT_ENABLED] = USE_SPEECH_INPUT_BROWSER
|
580 | 598 | current_app.config[CONFIG_SPEECH_OUTPUT_BROWSER_ENABLED] = USE_SPEECH_OUTPUT_BROWSER
|
581 | 599 | current_app.config[CONFIG_SPEECH_OUTPUT_AZURE_ENABLED] = USE_SPEECH_OUTPUT_AZURE
|
|
0 commit comments