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` 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() 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_data/dotenv_no_datasource_2 b/tests/unit_tests/dotenv_data/dotenv_no_datasource_2 new file mode 100644 index 0000000000..5d2b1ae373 --- /dev/null +++ b/tests/unit_tests/dotenv_data/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):