Skip to content

Commit e74a88b

Browse files
fix: Removing the dependency on Azure Key Vault & Truncate SQL response
fix: Removing the dependency on Azure Key Vault & Truncate SQL response
2 parents 83c5cdc + 9f3c92d commit e74a88b

File tree

7 files changed

+65
-88
lines changed

7 files changed

+65
-88
lines changed

Diff for: infra/deploy_backend_docker.bicep

+9-22
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ param solutionName string
44
@secure()
55
param appSettings object = {}
66
param appServicePlanId string
7+
@secure()
8+
param azureOpenAIKey string
9+
@secure()
10+
param azureAiProjectConnString string
11+
@secure()
12+
param azureSearchAdminKey string
713
param userassignedIdentityId string
8-
param keyVaultName string
914

1015
var imageName = 'DOCKER|kmcontainerreg.azurecr.io/km-api:${imageTag}'
1116
var name = '${solutionName}-api'
@@ -84,6 +89,9 @@ module appService 'deploy_app_service.bicep' = {
8489
appSettings: union(
8590
appSettings,
8691
{
92+
AZURE_OPENAI_API_KEY: azureOpenAIKey
93+
AZURE_AI_SEARCH_API_KEY: azureSearchAdminKey
94+
AZURE_AI_PROJECT_CONN_STRING:azureAiProjectConnString
8795
APPINSIGHTS_INSTRUMENTATIONKEY: reference(applicationInsightsId, '2015-05-01').InstrumentationKey
8896
REACT_APP_LAYOUT_CONFIG: reactAppLayoutConfig
8997
}
@@ -110,25 +118,4 @@ resource role 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2022-05-
110118
}
111119
}
112120

113-
resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
114-
name: keyVaultName
115-
}
116-
117-
var keyVaultSecretsOfficerId='b86a8fe4-44ce-4948-aee5-eccb2c155cd7'
118-
@description('The built-in role for Key Vault Secrets Officer.')
119-
resource keyVaultSecretsOfficerRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
120-
scope: subscription()
121-
name: keyVaultSecretsOfficerId
122-
}
123-
124-
resource keyVaultSecretsOfficerRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
125-
scope: keyVault
126-
name: guid(keyVault.id, keyVaultSecretsOfficerRoleDefinition.id)
127-
properties: {
128-
roleDefinitionId: keyVaultSecretsOfficerRoleDefinition.id
129-
principalId: appService.outputs.identityPrincipalId
130-
principalType: 'ServicePrincipal'
131-
}
132-
}
133-
134121
output appUrl string = appService.outputs.appUrl

Diff for: infra/main.bicep

+3-5
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ module backend_docker 'deploy_backend_docker.bicep'= {
194194
imageTag: imageTag
195195
appServicePlanId: hostingplan.outputs.name
196196
applicationInsightsId: aifoundry.outputs.applicationInsightsId
197+
azureOpenAIKey:keyVault.getSecret('AZURE-OPENAI-KEY')
198+
azureAiProjectConnString:keyVault.getSecret('AZURE-AI-PROJECT-CONN-STRING')
199+
azureSearchAdminKey:keyVault.getSecret('AZURE-SEARCH-KEY')
197200
solutionName: solutionPrefix
198201
userassignedIdentityId: managedIdentityModule.outputs.managedIdentityBackendAppOutput.id
199-
keyVaultName:aifoundry.outputs.keyvaultName
200202
appSettings:{
201203
AZURE_OPEN_AI_DEPLOYMENT_MODEL:gptModelName
202204
AZURE_OPEN_AI_ENDPOINT:aifoundry.outputs.aiServicesTarget
203205
AZURE_OPENAI_API_VERSION: azureOpenAIApiVersion
204206
AZURE_OPENAI_RESOURCE:aifoundry.outputs.aiServicesName
205-
AZURE_OPENAI_API_KEY:'AZURE-OPENAI-KEY'
206-
AZURE_KEY_VAULT_URL: kvault.outputs.keyvaultUri
207207
USE_CHAT_HISTORY_ENABLED:'True'
208208
AZURE_COSMOSDB_ACCOUNT: cosmosDBModule.outputs.cosmosAccountName
209209
AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: cosmosDBModule.outputs.cosmosContainerName
@@ -217,9 +217,7 @@ module backend_docker 'deploy_backend_docker.bicep'= {
217217
OPENAI_API_VERSION: azureOpenAIApiVersion
218218
AZURE_AI_SEARCH_ENDPOINT: aifoundry.outputs.aiSearchTarget
219219
AZURE_AI_SEARCH_INDEX: 'call_transcripts_index'
220-
AZURE_AI_SEARCH_API_KEY:'AZURE-SEARCH-KEY'
221220
USE_AI_PROJECT_CLIENT:'False'
222-
AZURE_AI_PROJECT_CONN_STRING:'AZURE-AI-PROJECT-CONN-STRING'
223221
DISPLAY_CHART_DEFAULT:'True'
224222
}
225223
}

Diff for: infra/main.json

+37-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.34.44.8038",
8-
"templateHash": "11969070936051168983"
8+
"templateHash": "1028263065130624134"
99
}
1010
},
1111
"parameters": {
@@ -1961,23 +1961,42 @@
19611961
"applicationInsightsId": {
19621962
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.applicationInsightsId.value]"
19631963
},
1964+
"azureOpenAIKey": {
1965+
"reference": {
1966+
"keyVault": {
1967+
"id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.KeyVault/vaults', reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value)]"
1968+
},
1969+
"secretName": "AZURE-OPENAI-KEY"
1970+
}
1971+
},
1972+
"azureAiProjectConnString": {
1973+
"reference": {
1974+
"keyVault": {
1975+
"id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.KeyVault/vaults', reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value)]"
1976+
},
1977+
"secretName": "AZURE-AI-PROJECT-CONN-STRING"
1978+
}
1979+
},
1980+
"azureSearchAdminKey": {
1981+
"reference": {
1982+
"keyVault": {
1983+
"id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.KeyVault/vaults', reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value)]"
1984+
},
1985+
"secretName": "AZURE-SEARCH-KEY"
1986+
}
1987+
},
19641988
"solutionName": {
19651989
"value": "[variables('solutionPrefix')]"
19661990
},
19671991
"userassignedIdentityId": {
19681992
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityBackendAppOutput.value.id]"
19691993
},
1970-
"keyVaultName": {
1971-
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value]"
1972-
},
19731994
"appSettings": {
19741995
"value": {
19751996
"AZURE_OPEN_AI_DEPLOYMENT_MODEL": "[parameters('gptModelName')]",
19761997
"AZURE_OPEN_AI_ENDPOINT": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.aiServicesTarget.value]",
19771998
"AZURE_OPENAI_API_VERSION": "[variables('azureOpenAIApiVersion')]",
19781999
"AZURE_OPENAI_RESOURCE": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.aiServicesName.value]",
1979-
"AZURE_OPENAI_API_KEY": "AZURE-OPENAI-KEY",
1980-
"AZURE_KEY_VAULT_URL": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_keyvault'), '2022-09-01').outputs.keyvaultUri.value]",
19812000
"USE_CHAT_HISTORY_ENABLED": "True",
19822001
"AZURE_COSMOSDB_ACCOUNT": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_cosmos_db'), '2022-09-01').outputs.cosmosAccountName.value]",
19832002
"AZURE_COSMOSDB_CONVERSATIONS_CONTAINER": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_cosmos_db'), '2022-09-01').outputs.cosmosContainerName.value]",
@@ -1990,9 +2009,7 @@
19902009
"OPENAI_API_VERSION": "[variables('azureOpenAIApiVersion')]",
19912010
"AZURE_AI_SEARCH_ENDPOINT": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.aiSearchTarget.value]",
19922011
"AZURE_AI_SEARCH_INDEX": "call_transcripts_index",
1993-
"AZURE_AI_SEARCH_API_KEY": "AZURE-SEARCH-KEY",
19942012
"USE_AI_PROJECT_CLIENT": "False",
1995-
"AZURE_AI_PROJECT_CONN_STRING": "AZURE-AI-PROJECT-CONN-STRING",
19962013
"DISPLAY_CHART_DEFAULT": "True"
19972014
}
19982015
}
@@ -2004,7 +2021,7 @@
20042021
"_generator": {
20052022
"name": "bicep",
20062023
"version": "0.34.44.8038",
2007-
"templateHash": "3648197818087330444"
2024+
"templateHash": "445807380408189331"
20082025
}
20092026
},
20102027
"parameters": {
@@ -2024,18 +2041,23 @@
20242041
"appServicePlanId": {
20252042
"type": "string"
20262043
},
2027-
"userassignedIdentityId": {
2028-
"type": "string"
2044+
"azureOpenAIKey": {
2045+
"type": "securestring"
20292046
},
2030-
"keyVaultName": {
2047+
"azureAiProjectConnString": {
2048+
"type": "securestring"
2049+
},
2050+
"azureSearchAdminKey": {
2051+
"type": "securestring"
2052+
},
2053+
"userassignedIdentityId": {
20312054
"type": "string"
20322055
}
20332056
},
20342057
"variables": {
20352058
"imageName": "[format('DOCKER|kmcontainerreg.azurecr.io/km-api:{0}', parameters('imageTag'))]",
20362059
"name": "[format('{0}-api', parameters('solutionName'))]",
2037-
"reactAppLayoutConfig": "{\r\n \"appConfig\": {\r\n \"THREE_COLUMN\": {\r\n \"DASHBOARD\": 50,\r\n \"CHAT\": 33,\r\n \"CHATHISTORY\": 17\r\n },\r\n \"TWO_COLUMN\": {\r\n \"DASHBOARD_CHAT\": {\r\n \"DASHBOARD\": 65,\r\n \"CHAT\": 35\r\n },\r\n \"CHAT_CHATHISTORY\": {\r\n \"CHAT\": 80,\r\n \"CHATHISTORY\": 20\r\n }\r\n }\r\n },\r\n \"charts\": [\r\n {\r\n \"id\": \"SATISFIED\",\r\n \"name\": \"Satisfied\",\r\n \"type\": \"card\",\r\n \"layout\": { \"row\": 1, \"column\": 1, \"height\": 11 }\r\n },\r\n {\r\n \"id\": \"TOTAL_CALLS\",\r\n \"name\": \"Total Calls\",\r\n \"type\": \"card\",\r\n \"layout\": { \"row\": 1, \"column\": 2, \"span\": 1 }\r\n },\r\n {\r\n \"id\": \"AVG_HANDLING_TIME\",\r\n \"name\": \"Average Handling Time\",\r\n \"type\": \"card\",\r\n \"layout\": { \"row\": 1, \"column\": 3, \"span\": 1 }\r\n },\r\n {\r\n \"id\": \"SENTIMENT\",\r\n \"name\": \"Topics Overview\",\r\n \"type\": \"donutchart\",\r\n \"layout\": { \"row\": 2, \"column\": 1, \"width\": 40, \"height\": 44.5 }\r\n },\r\n {\r\n \"id\": \"AVG_HANDLING_TIME_BY_TOPIC\",\r\n \"name\": \"Average Handling Time By Topic\",\r\n \"type\": \"bar\",\r\n \"layout\": { \"row\": 2, \"column\": 2, \"row-span\": 2, \"width\": 60 }\r\n },\r\n {\r\n \"id\": \"TOPICS\",\r\n \"name\": \"Trending Topics\",\r\n \"type\": \"table\",\r\n \"layout\": { \"row\": 3, \"column\": 1, \"span\": 2 }\r\n },\r\n {\r\n \"id\": \"KEY_PHRASES\",\r\n \"name\": \"Key Phrases\",\r\n \"type\": \"wordcloud\",\r\n \"layout\": { \"row\": 3, \"column\": 2, \"height\": 44.5 }\r\n }\r\n ]\r\n}",
2038-
"keyVaultSecretsOfficerId": "b86a8fe4-44ce-4948-aee5-eccb2c155cd7"
2060+
"reactAppLayoutConfig": "{\r\n \"appConfig\": {\r\n \"THREE_COLUMN\": {\r\n \"DASHBOARD\": 50,\r\n \"CHAT\": 33,\r\n \"CHATHISTORY\": 17\r\n },\r\n \"TWO_COLUMN\": {\r\n \"DASHBOARD_CHAT\": {\r\n \"DASHBOARD\": 65,\r\n \"CHAT\": 35\r\n },\r\n \"CHAT_CHATHISTORY\": {\r\n \"CHAT\": 80,\r\n \"CHATHISTORY\": 20\r\n }\r\n }\r\n },\r\n \"charts\": [\r\n {\r\n \"id\": \"SATISFIED\",\r\n \"name\": \"Satisfied\",\r\n \"type\": \"card\",\r\n \"layout\": { \"row\": 1, \"column\": 1, \"height\": 11 }\r\n },\r\n {\r\n \"id\": \"TOTAL_CALLS\",\r\n \"name\": \"Total Calls\",\r\n \"type\": \"card\",\r\n \"layout\": { \"row\": 1, \"column\": 2, \"span\": 1 }\r\n },\r\n {\r\n \"id\": \"AVG_HANDLING_TIME\",\r\n \"name\": \"Average Handling Time\",\r\n \"type\": \"card\",\r\n \"layout\": { \"row\": 1, \"column\": 3, \"span\": 1 }\r\n },\r\n {\r\n \"id\": \"SENTIMENT\",\r\n \"name\": \"Topics Overview\",\r\n \"type\": \"donutchart\",\r\n \"layout\": { \"row\": 2, \"column\": 1, \"width\": 40, \"height\": 44.5 }\r\n },\r\n {\r\n \"id\": \"AVG_HANDLING_TIME_BY_TOPIC\",\r\n \"name\": \"Average Handling Time By Topic\",\r\n \"type\": \"bar\",\r\n \"layout\": { \"row\": 2, \"column\": 2, \"row-span\": 2, \"width\": 60 }\r\n },\r\n {\r\n \"id\": \"TOPICS\",\r\n \"name\": \"Trending Topics\",\r\n \"type\": \"table\",\r\n \"layout\": { \"row\": 3, \"column\": 1, \"span\": 2 }\r\n },\r\n {\r\n \"id\": \"KEY_PHRASES\",\r\n \"name\": \"Key Phrases\",\r\n \"type\": \"wordcloud\",\r\n \"layout\": { \"row\": 3, \"column\": 2, \"height\": 44.5 }\r\n }\r\n ]\r\n}"
20392061
},
20402062
"resources": [
20412063
{
@@ -2051,20 +2073,6 @@
20512073
"[resourceId('Microsoft.Resources/deployments', format('{0}-app-module', variables('name')))]"
20522074
]
20532075
},
2054-
{
2055-
"type": "Microsoft.Authorization/roleAssignments",
2056-
"apiVersion": "2022-04-01",
2057-
"scope": "[format('Microsoft.KeyVault/vaults/{0}', parameters('keyVaultName'))]",
2058-
"name": "[guid(resourceId('Microsoft.KeyVault/vaults', parameters('keyVaultName')), subscriptionResourceId('Microsoft.Authorization/roleDefinitions', variables('keyVaultSecretsOfficerId')))]",
2059-
"properties": {
2060-
"roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', variables('keyVaultSecretsOfficerId'))]",
2061-
"principalId": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-app-module', variables('name'))), '2022-09-01').outputs.identityPrincipalId.value]",
2062-
"principalType": "ServicePrincipal"
2063-
},
2064-
"dependsOn": [
2065-
"[resourceId('Microsoft.Resources/deployments', format('{0}-app-module', variables('name')))]"
2066-
]
2067-
},
20682076
{
20692077
"type": "Microsoft.Resources/deployments",
20702078
"apiVersion": "2022-09-01",
@@ -2088,7 +2096,7 @@
20882096
"value": "[parameters('userassignedIdentityId')]"
20892097
},
20902098
"appSettings": {
2091-
"value": "[union(parameters('appSettings'), createObject('APPINSIGHTS_INSTRUMENTATIONKEY', reference(parameters('applicationInsightsId'), '2015-05-01').InstrumentationKey, 'REACT_APP_LAYOUT_CONFIG', variables('reactAppLayoutConfig')))]"
2099+
"value": "[union(parameters('appSettings'), createObject('AZURE_OPENAI_API_KEY', parameters('azureOpenAIKey'), 'AZURE_AI_SEARCH_API_KEY', parameters('azureSearchAdminKey'), 'AZURE_AI_PROJECT_CONN_STRING', parameters('azureAiProjectConnString'), 'APPINSIGHTS_INSTRUMENTATIONKEY', reference(parameters('applicationInsightsId'), '2015-05-01').InstrumentationKey, 'REACT_APP_LAYOUT_CONFIG', variables('reactAppLayoutConfig')))]"
20922100
}
20932101
},
20942102
"template": {
@@ -2273,7 +2281,6 @@
22732281
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry')]",
22742282
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_cosmos_db')]",
22752283
"[resourceId('Microsoft.Resources/deployments', 'deploy_app_service_plan')]",
2276-
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_keyvault')]",
22772284
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity')]",
22782285
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_sql_db')]"
22792286
]

Diff for: src/api/ApiApp.Dockerfile

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
FROM python:3.11-alpine
22

33
# Install system dependencies required for building and running the application
4-
RUN apk add --no-cache --virtual .build-deps \
5-
build-base \
6-
libffi-dev \
7-
openssl-dev \
4+
RUN apk add --no-cache --virtual .build-deps \
5+
build-base \
6+
libffi-dev \
7+
openssl-dev \
88
curl \
9-
unixodbc-dev \
10-
libpq
9+
unixodbc-dev \
10+
libpq \
11+
opus-dev \
12+
libvpx-dev
1113

1214
# Download and install Microsoft ODBC Driver and MSSQL tools
1315
RUN curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.10.6.1-1_amd64.apk \
@@ -23,7 +25,8 @@ WORKDIR /app
2325
COPY ./requirements.txt .
2426

2527
# Install Python dependencies
26-
RUN pip install --no-cache-dir -r requirements.txt && rm -rf /root/.cache
28+
RUN pip install --upgrade pip setuptools wheel \
29+
&& pip install --no-cache-dir -r requirements.txt && rm -rf /root/.cache
2730

2831
# Copy the backend application code into the container
2932
COPY ./ .
@@ -32,4 +35,4 @@ COPY ./ .
3235
EXPOSE 80
3336

3437
# Start the application using Uvicorn
35-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"]
38+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"]

0 commit comments

Comments
 (0)