Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs and bugfix caused by DATASOURCE_TYPE setting #881

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading