From ca346011b79b0ee9a0f922190021b3df24a2c5a7 Mon Sep 17 00:00:00 2001 From: adrienohana <61504470+adrienohana@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:20:18 +0200 Subject: [PATCH] added interactive login for azure cognitive search vector store (#11360) **Description:** Previously if the access to Azure Cognitive Search was not done via an API key, the default credential was called which doesn't allow to use an interactive login. I simply added the option to use "INTERACTIVE" as a key name, and this will launch a login window upon initialization of the AzureSearch object. --- libs/langchain/langchain/vectorstores/azuresearch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/langchain/langchain/vectorstores/azuresearch.py b/libs/langchain/langchain/vectorstores/azuresearch.py index 84b3db36ff..366487753a 100644 --- a/libs/langchain/langchain/vectorstores/azuresearch.py +++ b/libs/langchain/langchain/vectorstores/azuresearch.py @@ -77,7 +77,7 @@ def _get_search_client( ) -> SearchClient: from azure.core.credentials import AzureKeyCredential from azure.core.exceptions import ResourceNotFoundError - from azure.identity import DefaultAzureCredential + from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential from azure.search.documents import SearchClient from azure.search.documents.indexes import SearchIndexClient from azure.search.documents.indexes.models import ( @@ -93,6 +93,9 @@ def _get_search_client( default_fields = default_fields or [] if key is None: credential = DefaultAzureCredential() + elif key.upper() == "INTERACTIVE": + credential = InteractiveBrowserCredential() + credential.get_token("https://search.azure.com/.default") else: credential = AzureKeyCredential(key) index_client: SearchIndexClient = SearchIndexClient(