Skip to content

Commit

Permalink
Update docs and bugfix caused by DATASOURCE_TYPE setting (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhahn authored May 25, 2024
1 parent 78d0402 commit b518ba0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
58 changes: 31 additions & 27 deletions backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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=
AZURE_OPENAI_EMBEDDING_KEY=
14 changes: 14 additions & 0 deletions tests/unit_tests/dotenv_data/dotenv_no_datasource_2
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion tests/unit_tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b518ba0

Please sign in to comment.