Skip to content

Commit

Permalink
Fix comma/pipe separator issue and improve local dev loop (#483)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Widder <[email protected]>
  • Loading branch information
sarah-widder and sarah-widder authored Jan 6, 2024
1 parent 8695112 commit f187a36
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ AZURE_OPENAI_EMBEDDING_NAME=
AZURE_COSMOSDB_ACCOUNT=
AZURE_COSMOSDB_DATABASE=
AZURE_COSMOSDB_CONVERSATIONS_CONTAINER=
AZURE_COSMOSDB_ACCOUNT_KEY=
AZURE_COSMOSDB_ACCOUNT_KEY=
AZURE_COSMOSDB_MONGO_VCORE_DATABASE=
AZURE_COSMOSDB_MONGO_VCORE_CONNECTION_STRING=
AZURE_COSMOSDB_MONGO_VCORE_CONTAINER=
AZURE_COSMOSDB_MONGO_VCORE_INDEX=
AZURE_COSMOSDB_MONGO_VCORE_CONTENT_COLUMNS=
AZURE_COSMOSDB_MONGO_VCORE_VECTOR_COLUMNS=
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Sample UI Backend",
"type": "python",
"request": "launch",
"module": "flask",
"envFile": "${workspaceFolder}/.env",
"args": ["run", "--no-debugger", "--no-reload", "-p 5000"],
"justMyCode": true
}
]
}
18 changes: 12 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ def should_use_data():
def format_as_ndjson(obj: dict) -> str:
return json.dumps(obj, ensure_ascii=False) + "\n"

def parse_multi_columns(columns: str) -> list:
if "|" in columns:
return columns.split("|")
else:
return columns.split(",")

def fetchUserGroups(userToken, nextLink=None):
# Recursively fetch group membership
if nextLink:
Expand Down Expand Up @@ -244,11 +250,11 @@ def prepare_body_headers_with_data(request):
"key": AZURE_SEARCH_KEY,
"indexName": AZURE_SEARCH_INDEX,
"fieldsMapping": {
"contentFields": AZURE_SEARCH_CONTENT_COLUMNS.split("|") if AZURE_SEARCH_CONTENT_COLUMNS else [],
"contentFields": parse_multi_columns(AZURE_SEARCH_CONTENT_COLUMNS) if AZURE_SEARCH_CONTENT_COLUMNS else [],
"titleField": AZURE_SEARCH_TITLE_COLUMN if AZURE_SEARCH_TITLE_COLUMN else None,
"urlField": AZURE_SEARCH_URL_COLUMN if AZURE_SEARCH_URL_COLUMN else None,
"filepathField": AZURE_SEARCH_FILENAME_COLUMN if AZURE_SEARCH_FILENAME_COLUMN else None,
"vectorFields": AZURE_SEARCH_VECTOR_COLUMNS.split("|") if AZURE_SEARCH_VECTOR_COLUMNS else []
"vectorFields": parse_multi_columns(AZURE_SEARCH_VECTOR_COLUMNS) if AZURE_SEARCH_VECTOR_COLUMNS else []
},
"inScope": True if AZURE_SEARCH_ENABLE_IN_DOMAIN.lower() == "true" else False,
"topNDocuments": AZURE_SEARCH_TOP_K,
Expand All @@ -272,11 +278,11 @@ def prepare_body_headers_with_data(request):
"databaseName": AZURE_COSMOSDB_MONGO_VCORE_DATABASE,
"containerName": AZURE_COSMOSDB_MONGO_VCORE_CONTAINER,
"fieldsMapping": {
"contentFields": AZURE_COSMOSDB_MONGO_VCORE_CONTENT_COLUMNS.split("|") if AZURE_COSMOSDB_MONGO_VCORE_CONTENT_COLUMNS else [],
"contentFields": parse_multi_columns(AZURE_COSMOSDB_MONGO_VCORE_CONTENT_COLUMNS) if AZURE_COSMOSDB_MONGO_VCORE_CONTENT_COLUMNS else [],
"titleField": AZURE_COSMOSDB_MONGO_VCORE_TITLE_COLUMN if AZURE_COSMOSDB_MONGO_VCORE_TITLE_COLUMN else None,
"urlField": AZURE_COSMOSDB_MONGO_VCORE_URL_COLUMN if AZURE_COSMOSDB_MONGO_VCORE_URL_COLUMN else None,
"filepathField": AZURE_COSMOSDB_MONGO_VCORE_FILENAME_COLUMN if AZURE_COSMOSDB_MONGO_VCORE_FILENAME_COLUMN else None,
"vectorFields": AZURE_COSMOSDB_MONGO_VCORE_VECTOR_COLUMNS.split("|") if AZURE_COSMOSDB_MONGO_VCORE_VECTOR_COLUMNS else []
"vectorFields": parse_multi_columns(AZURE_COSMOSDB_MONGO_VCORE_VECTOR_COLUMNS) if AZURE_COSMOSDB_MONGO_VCORE_VECTOR_COLUMNS else []
},
"inScope": True if AZURE_COSMOSDB_MONGO_VCORE_ENABLE_IN_DOMAIN.lower() == "true" else False,
"topNDocuments": AZURE_COSMOSDB_MONGO_VCORE_TOP_K,
Expand Down Expand Up @@ -304,11 +310,11 @@ def prepare_body_headers_with_data(request):
"encodedApiKey": ELASTICSEARCH_ENCODED_API_KEY,
"indexName": ELASTICSEARCH_INDEX,
"fieldsMapping": {
"contentFields": ELASTICSEARCH_CONTENT_COLUMNS.split("|") if ELASTICSEARCH_CONTENT_COLUMNS else [],
"contentFields": parse_multi_columns(ELASTICSEARCH_CONTENT_COLUMNS) if ELASTICSEARCH_CONTENT_COLUMNS else [],
"titleField": ELASTICSEARCH_TITLE_COLUMN if ELASTICSEARCH_TITLE_COLUMN else None,
"urlField": ELASTICSEARCH_URL_COLUMN if ELASTICSEARCH_URL_COLUMN else None,
"filepathField": ELASTICSEARCH_FILENAME_COLUMN if ELASTICSEARCH_FILENAME_COLUMN else None,
"vectorFields": ELASTICSEARCH_VECTOR_COLUMNS.split("|") if ELASTICSEARCH_VECTOR_COLUMNS else []
"vectorFields": parse_multi_columns(ELASTICSEARCH_VECTOR_COLUMNS) if ELASTICSEARCH_VECTOR_COLUMNS else []
},
"inScope": True if ELASTICSEARCH_ENABLE_IN_DOMAIN.lower() == "true" else False,
"topNDocuments": int(ELASTICSEARCH_TOP_K),
Expand Down

0 comments on commit f187a36

Please sign in to comment.