From ddb2a5236f891a85ec9d5be3e1094b47d35b40fd Mon Sep 17 00:00:00 2001 From: Abigail Hartman Date: Fri, 24 May 2024 18:17:13 -0700 Subject: [PATCH 1/4] Update docs with new required app setting DATASOURCE_TYPE --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 48d65e6ab9..72c0ec169b 100644 --- a/README.md +++ b/README.md @@ -46,13 +46,14 @@ Please see the [section below](#add-an-identity-provider) for important informat 3. You can see the local running app at http://127.0.0.1:50505. -#### Local Setup: Chat with your data (Preview) +#### Local Setup: Chat with your data using Azure Cognitive Search [More information about Azure OpenAI on your data](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/concepts/use-your-data) 1. Update the `AZURE_OPENAI_*` environment variables as described above. 2. To connect to your data, you need to specify an Azure Cognitive Search index to use. You can [create this index yourself](https://learn.microsoft.com/en-us/azure/search/search-get-started-portal) or use the [Azure AI Studio](https://oai.azure.com/portal/chat) to create the index for you. These variables are required when adding your data with Azure AI Search: + - `DATASOURCE_TYPE` (should be set to `AzureCognitiveSearch`) - `AZURE_SEARCH_SERVICE` - `AZURE_SEARCH_INDEX` - `AZURE_SEARCH_KEY` From 8b8b762358d7a35e8bef5a3654ac88da07b72897 Mon Sep 17 00:00:00 2001 From: Abigail Hartman Date: Fri, 24 May 2024 18:49:25 -0700 Subject: [PATCH 2/4] Update to fix issue caused by inconsistent use of DATASOURCE_TYPE variable when deploying from the studio --- backend/settings.py | 58 ++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/backend/settings.py b/backend/settings.py index 0fe0ba59e9..133ffbdc41 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -683,35 +683,39 @@ def set_chat_history_settings(self) -> Self: @model_validator(mode="after") def set_datasource_settings(self) -> Self: - if self.base_settings.datasource_type == "AzureCognitiveSearch": - self.datasource = _AzureSearchSettings(settings=self, _env_file=DOTENV_PATH) - logging.debug("Using Azure Cognitive Search") - - elif self.base_settings.datasource_type == "AzureCosmosDB": - self.datasource = _AzureCosmosDbMongoVcoreSettings(settings=self, _env_file=DOTENV_PATH) - logging.debug("Using Azure CosmosDB Mongo vcore") - - elif self.base_settings.datasource_type == "Elasticsearch": - self.datasource = _ElasticsearchSettings(settings=self, _env_file=DOTENV_PATH) - logging.debug("Using Elasticsearch") - - elif self.base_settings.datasource_type == "Pinecone": - self.datasource = _PineconeSettings(settings=self, _env_file=DOTENV_PATH) - logging.debug("Using Pinecone") - - elif self.base_settings.datasource_type == "AzureMLIndex": - self.datasource = _AzureMLIndexSettings(settings=self, _env_file=DOTENV_PATH) - logging.debug("Using Azure ML Index") - - elif self.base_settings.datasource_type == "AzureSqlServer": - self.datasource = _AzureSqlServerSettings(settings=self, _env_file=DOTENV_PATH) - logging.debug("Using SQL Server") + try: + if self.base_settings.datasource_type == "AzureCognitiveSearch": + self.datasource = _AzureSearchSettings(settings=self, _env_file=DOTENV_PATH) + logging.debug("Using Azure Cognitive Search") - else: - self.datasource = None - logging.warning("No datasource configuration found in the environment -- calls will be made to Azure OpenAI without grounding data.") + elif self.base_settings.datasource_type == "AzureCosmosDB": + self.datasource = _AzureCosmosDbMongoVcoreSettings(settings=self, _env_file=DOTENV_PATH) + logging.debug("Using Azure CosmosDB Mongo vcore") - return self + elif self.base_settings.datasource_type == "Elasticsearch": + self.datasource = _ElasticsearchSettings(settings=self, _env_file=DOTENV_PATH) + logging.debug("Using Elasticsearch") + + elif self.base_settings.datasource_type == "Pinecone": + self.datasource = _PineconeSettings(settings=self, _env_file=DOTENV_PATH) + logging.debug("Using Pinecone") + + elif self.base_settings.datasource_type == "AzureMLIndex": + self.datasource = _AzureMLIndexSettings(settings=self, _env_file=DOTENV_PATH) + logging.debug("Using Azure ML Index") + + elif self.base_settings.datasource_type == "AzureSqlServer": + self.datasource = _AzureSqlServerSettings(settings=self, _env_file=DOTENV_PATH) + logging.debug("Using SQL Server") + + else: + self.datasource = None + logging.warning("No datasource configuration found in the environment -- calls will be made to Azure OpenAI without grounding data.") + + return self + + except ValidationError: + logging.warning("No datasource configuration found in the environment -- calls will be made to Azure OpenAI without grounding data.") app_settings = _AppSettings() From a31674d724bd8e71ee919b8e74b10bc1f5b1c3cb Mon Sep 17 00:00:00 2001 From: Abigail Hartman Date: Fri, 24 May 2024 19:10:08 -0700 Subject: [PATCH 3/4] Add unit tests --- ...dotenv_no_datasource => dotenv_no_datasource_1} | 2 +- tests/unit_tests/dotenv_no_datasource_2 | 14 ++++++++++++++ tests/unit_tests/test_settings.py | 8 +++++++- 3 files changed, 22 insertions(+), 2 deletions(-) rename tests/unit_tests/dotenv_data/{dotenv_no_datasource => dotenv_no_datasource_1} (94%) create mode 100644 tests/unit_tests/dotenv_no_datasource_2 diff --git a/tests/unit_tests/dotenv_data/dotenv_no_datasource b/tests/unit_tests/dotenv_data/dotenv_no_datasource_1 similarity index 94% rename from tests/unit_tests/dotenv_data/dotenv_no_datasource rename to tests/unit_tests/dotenv_data/dotenv_no_datasource_1 index 057ebb2cdd..63cc59d24b 100644 --- a/tests/unit_tests/dotenv_data/dotenv_no_datasource +++ b/tests/unit_tests/dotenv_data/dotenv_no_datasource_1 @@ -10,4 +10,4 @@ AZURE_OPENAI_STREAM=False AZURE_OPENAI_ENDPOINT=https://dummy.openai.azure.com/ AZURE_OPENAI_EMBEDDING_NAME= AZURE_OPENAI_EMBEDDING_ENDPOINT= -AZURE_OPENAI_EMBEDDING_KEY= \ No newline at end of file +AZURE_OPENAI_EMBEDDING_KEY= diff --git a/tests/unit_tests/dotenv_no_datasource_2 b/tests/unit_tests/dotenv_no_datasource_2 new file mode 100644 index 0000000000..5d2b1ae373 --- /dev/null +++ b/tests/unit_tests/dotenv_no_datasource_2 @@ -0,0 +1,14 @@ +AZURE_OPENAI_MODEL=my_model +AZURE_OPENAI_KEY=dummy +AZURE_OPENAI_TEMPERATURE=0 +AZURE_OPENAI_TOP_P=1.0 +AZURE_OPENAI_MAX_TOKENS=1000 +AZURE_OPENAI_STOP_SEQUENCE= +AZURE_OPENAI_SYSTEM_MESSAGE=You are an AI assistant that helps people find information. +AZURE_OPENAI_PREVIEW_API_VERSION=2024-05-01-preview +AZURE_OPENAI_STREAM=False +AZURE_OPENAI_ENDPOINT=https://dummy.openai.azure.com/ +AZURE_OPENAI_EMBEDDING_NAME= +AZURE_OPENAI_EMBEDDING_ENDPOINT= +AZURE_OPENAI_EMBEDDING_KEY= +DATASOURCE_TYPE=AzureCognitiveSearch \ No newline at end of file diff --git a/tests/unit_tests/test_settings.py b/tests/unit_tests/test_settings.py index fdd5adaf63..3bf3da2228 100644 --- a/tests/unit_tests/test_settings.py +++ b/tests/unit_tests/test_settings.py @@ -23,11 +23,17 @@ def app_settings(dotenv_path): yield getattr(settings_module, "app_settings") -def test_dotenv_no_datasource(app_settings): +def test_dotenv_no_datasource_1(app_settings): # Validate model object assert app_settings.base_settings.datasource_type is None assert app_settings.datasource is None assert app_settings.azure_openai is not None + + +def test_dotenv_no_datasource_2(app_settings): + # Validate model object + assert app_settings.datasource is None + assert app_settings.azure_openai is not None def test_dotenv_with_azure_search_success(app_settings): From 32ec5e3d32bbe53ca0d15ac4664969c916272832 Mon Sep 17 00:00:00 2001 From: Abigail Hartman Date: Fri, 24 May 2024 19:12:41 -0700 Subject: [PATCH 4/4] Move file to correct location --- tests/unit_tests/{ => dotenv_data}/dotenv_no_datasource_2 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unit_tests/{ => dotenv_data}/dotenv_no_datasource_2 (100%) diff --git a/tests/unit_tests/dotenv_no_datasource_2 b/tests/unit_tests/dotenv_data/dotenv_no_datasource_2 similarity index 100% rename from tests/unit_tests/dotenv_no_datasource_2 rename to tests/unit_tests/dotenv_data/dotenv_no_datasource_2