forked from Azure/Vector-Search-AI-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azuredeploy.bicep
397 lines (362 loc) · 10.5 KB
/
azuredeploy.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
@description('Location where all resources will be deployed. This value defaults to the **East US** region.')
@allowed([
'southcentralus'
'eastus'
'westeurope'
])
param location string = 'eastus'
@description('''
Unique name for the deployed services below. Max length 15 characters, alphanumeric only:
- Azure Cosmos DB for NoSQL
- Azure Cosmos DB for MongoDB vCore
- Azure OpenAI
- Azure App Service
- Azure Functions
The name defaults to a unique string generated from the resource group identifier.
''')
@maxLength(15)
param name string = uniqueString(resourceGroup().id)
@description('Specifies the SKU for the Azure App Service plan. Defaults to **B1**')
@allowed([
'B1'
'S1'
])
param appServiceSku string = 'B1'
@description('Specifies the SKU for the Azure OpenAI resource. Defaults to **S0**')
@allowed([
'S0'
])
param openAiSku string = 'S0'
@description('MongoDb vCore user Name. No dashes.')
param mongoDbUserName string
@description('MongoDb vCore password. 8-256 characters, 3 of the following: lower case, upper case, numeric, symbol.')
@minLength(8)
@maxLength(256)
@secure()
param mongoDbPassword string
@description('Git repository URL for the application source. This defaults to the [`Azure/BuildYourOwnCopilot`](https://github.com/Azure/BuildYourOwnCopilot) repository.')
param appGitRepository string = 'https://github.com/Azure/BuildYourOwnCopilot.git'
@description('Git repository branch for the application source. This defaults to the [**MongovCore** branch of the `Azure/BuildYourOwnCopilot`](https://github.com/Azure/BuildYourOwnCopilot/tree/MongovCore) repository.')
param appGetRepositoryBranch string = 'MongovCore'
var openAiSettings = {
name: '${name}-openai'
sku: openAiSku
maxConversationBytes: '2000'
completionsModel: {
name: 'gpt-35-turbo'
version: '0301'
deployment: {
name: 'completions'
}
}
embeddingsModel: {
name: 'text-embedding-ada-002'
version: '2'
deployment: {
name: 'embeddings'
}
}
}
var deployedRegion = {
'East US': {
armName: toLower('eastus')
}
'South Central US': {
armName: toLower('southcentralus')
}
'West Europe': {
armName: toLower('westeurope')
}
}
var cosmosDbSettings = {
name: '${name}-cosmos-nosql'
databaseName: 'vsai-database'
}
var mongovCoreSettings = {
mongoClusterName: '${name}-mongo'
mongoClusterLogin: mongoDbUserName
mongoClusterPassword: mongoDbPassword
}
var cosmosContainers = {
embeddingContainer: {
name: 'embedding'
partitionKeyPath : '/id'
}
completionsContainer: {
name: 'completions'
partitionKeyPath: '/sessionId'
}
productContainer: {
name: 'product'
partitionKeyPath: '/categoryId'
}
customerContainer: {
name: 'customer'
partitionKeyPath: '/customerId'
}
leasesContainer: {
name: 'leases'
partitionKeyPath: '/id'
}
}
var appServiceSettings = {
plan: {
name: '${name}-web-plan'
sku: appServiceSku
}
web: {
name: '${name}-web'
git: {
repo: appGitRepository
branch: appGetRepositoryBranch
}
}
function: {
name: '${name}-function'
git: {
repo: appGitRepository
branch: appGetRepositoryBranch
}
}
}
resource cosmosDbAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = {
name: cosmosDbSettings.name
location: location
kind: 'GlobalDocumentDB'
properties: {
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
}
databaseAccountOfferType: 'Standard'
locations: [
{
failoverPriority: 0
isZoneRedundant: false
locationName: location
}
]
capabilities: [
{
name: 'EnableServerless'
}
]
}
}
resource cosmosDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-08-15' = {
parent: cosmosDbAccount
name: cosmosDbSettings.databaseName
properties: {
resource: {
id: cosmosDbSettings.databaseName
}
}
}
resource cosmosContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-08-15' = [for container in items(cosmosContainers): {
parent: cosmosDatabase
name: container.value.name
properties: {
resource: {
id: container.value.name
partitionKey: {
paths: [
container.value.partitionKeyPath
]
kind: 'Hash'
version: 2
}
}
}
}]
resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2023-03-01-preview' = {
name: mongovCoreSettings.mongoClusterName
location: location
properties: {
administratorLogin: mongovCoreSettings.mongoClusterLogin
administratorLoginPassword: mongovCoreSettings.mongoClusterPassword
serverVersion: '5.0'
nodeGroupSpecs: [
{
kind: 'Shard'
sku: 'M30'
diskSizeGB: 128
enableHa: false
nodeCount: 1
}
]
}
}
resource mongoFirewallRulesAllowAzure 'Microsoft.DocumentDB/mongoClusters/firewallRules@2023-03-01-preview' = {
parent: mongoCluster
name: 'allowAzure'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
resource mongoFirewallRulesAllowAll 'Microsoft.DocumentDB/mongoClusters/firewallRules@2023-03-01-preview' = {
parent: mongoCluster
name: 'allowAll'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
}
resource openAiAccount 'Microsoft.CognitiveServices/accounts@2022-12-01' = {
name: openAiSettings.name
location: location
sku: {
name: openAiSettings.sku
}
kind: 'OpenAI'
properties: {
customSubDomainName: openAiSettings.name
publicNetworkAccess: 'Enabled'
}
}
resource openAiEmbeddingsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2022-12-01' = {
parent: openAiAccount
name: openAiSettings.embeddingsModel.deployment.name
properties: {
model: {
format: 'OpenAI'
name: openAiSettings.embeddingsModel.name
version: openAiSettings.embeddingsModel.version
}
scaleSettings: {
scaleType: 'Standard'
}
}
}
resource openAiCompletionsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2022-12-01' = {
parent: openAiAccount
name: openAiSettings.completionsModel.deployment.name
properties: {
model: {
format: 'OpenAI'
name: openAiSettings.completionsModel.name
version: openAiSettings.completionsModel.version
}
scaleSettings: {
scaleType: 'Standard'
}
}
}
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
name: appServiceSettings.plan.name
location: location
sku: {
name: appServiceSettings.plan.sku
}
}
resource appServiceWeb 'Microsoft.Web/sites@2022-03-01' = {
name: appServiceSettings.web.name
location: location
properties: {
serverFarmId: appServicePlan.id
httpsOnly: true
}
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
name: '${name}fnstorage'
location: location
kind: 'Storage'
sku: {
name: 'Standard_LRS'
}
}
resource appServiceFunction 'Microsoft.Web/sites@2022-03-01' = {
name: appServiceSettings.function.name
location: location
kind: 'functionapp'
properties: {
serverFarmId: appServicePlan.id
httpsOnly: true
siteConfig: {
alwaysOn: true
}
}
dependsOn: [
storageAccount
]
}
resource appServiceWebSettings 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appServiceWeb
name: 'appsettings'
kind: 'string'
properties: {
APPINSIGHTS_INSTRUMENTATIONKEY: appServiceWebInsights.properties.InstrumentationKey
COSMOSDB__ENDPOINT: cosmosDbAccount.properties.documentEndpoint
COSMOSDB__KEY: cosmosDbAccount.listKeys().primaryMasterKey
COSMOSDB__DATABASE: cosmosDatabase.name
COSMOSDB__CONTAINERS: 'completions,product,customer'
OPENAI__ENDPOINT: openAiAccount.properties.endpoint
OPENAI__KEY: openAiAccount.listKeys().key1
OPENAI__EMBEDDINGSDEPLOYMENT: openAiEmbeddingsModelDeployment.name
OPENAI__COMPLETIONSDEPLOYMENT: openAiCompletionsModelDeployment.name
OPENAI__MAXCONVERSATIONBYTES: openAiSettings.maxConversationBytes
MONGODB__CONNECTION: 'mongodb+srv://${mongovCoreSettings.mongoClusterLogin}:${mongovCoreSettings.mongoClusterPassword}@${mongovCoreSettings.mongoClusterName}.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000'
MONGODB__DATABASENAME: 'vectordb'
MONGODB__COLLECTIONNAME: 'vectors'
MONGODB__MAXVECTORSEARCHRESULTS: '10'
}
}
resource appServiceFunctionSettings 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appServiceFunction
name: 'appsettings'
kind: 'string'
properties: {
AzureWebJobsStorage: 'DefaultEndpointsProtocol=https;AccountName=${name}fnstorage;EndpointSuffix=core.windows.net;AccountKey=${storageAccount.listKeys().keys[0].value}'
APPINSIGHTS_INSTRUMENTATIONKEY: appServiceFunctionsInsights.properties.ConnectionString
FUNCTIONS_EXTENSION_VERSION: '~4'
FUNCTIONS_WORKER_RUNTIME: 'dotnet'
CosmosDBConnection: cosmosDbAccount.listConnectionStrings().connectionStrings[0].connectionString
OPENAI__ENDPOINT: openAiAccount.properties.endpoint
OPENAI__KEY: openAiAccount.listKeys().key1
OPENAI__EMBEDDINGSDEPLOYMENT: openAiEmbeddingsModelDeployment.name
OPENAI__MAXTOKENS: '8191'
MONGODB__CONNECTION: 'mongodb+srv://${mongovCoreSettings.mongoClusterLogin}:${mongovCoreSettings.mongoClusterPassword}@${mongovCoreSettings.mongoClusterName}.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000'
MONGODB__DATABASENAME: 'vectordb'
MONGODB__COLLECTIONNAME: 'vectors'
}
}
resource appServiceWebDeployment 'Microsoft.Web/sites/sourcecontrols@2021-03-01' = {
parent: appServiceWeb
name: 'web'
properties: {
repoUrl: appServiceSettings.web.git.repo
branch: appServiceSettings.web.git.branch
isManualIntegration: true
}
dependsOn: [
appServiceWebSettings
]
}
resource appServiceFunctionsDeployment 'Microsoft.Web/sites/sourcecontrols@2021-03-01' = {
parent: appServiceFunction
name: 'web'
properties: {
repoUrl: appServiceSettings.web.git.repo
branch: appServiceSettings.web.git.branch
isManualIntegration: true
}
dependsOn: [
appServiceFunctionSettings
]
}
resource appServiceFunctionsInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appServiceFunction.name
location: location
kind: 'web'
properties: {
Application_Type: 'web'
}
}
resource appServiceWebInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appServiceWeb.name
location: location
kind: 'web'
properties: {
Application_Type: 'web'
}
}
output deployedUrl string = appServiceWeb.properties.defaultHostName