forked from Azure/Vector-Search-AI-Assistant-MongoDBvCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazuredeploy.bicep
More file actions
304 lines (280 loc) · 9.19 KB
/
azuredeploy.bicep
File metadata and controls
304 lines (280 loc) · 9.19 KB
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
@description('Location where all resources will be deployed. This value defaults to the **East US** region.')
@allowed([
'australiaeast'
'canadaeast'
'westeurope'
'francecentral'
'japaneast'
'swedencentral'
'switzerlandnorth'
'uksouth'
'eastus'
'eastus2'
'northcentralus'
'southcentralus'
])
param location string = 'eastus'
@description('Unique name for the deployed services below. Max length 15 characters, alphanumeric only:\r\n- Azure Cosmos DB for MongoDB vCore\r\n- Azure OpenAI Service\r\n- Azure App Service\r\n- Azure Functions\r\n\r\nThe name defaults to a unique string generated from the resource group identifier.\r\n')
@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('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/Vector-Search-Ai-Assistant`](https://github.com/Azure/Vector-Search-AI-Assistant-MongoDBvCore.git) repository.')
param appGitRepository string = 'https://github.com/Azure/Vector-Search-AI-Assistant-MongoDBvCore.git'
@description('Git repository branch for the application source. This defaults to the [**main** branch of the `Azure/Vector-Search-Ai-Assistant-MongoDBvCore`](https://github.com/Azure/Vector-Search-AI-Assistant-MongoDBvCore/tree/main) repository.')
param appGetRepositoryBranch string = 'main'
var openAiSettings = {
name: '${name}-openai'
sku: 'S0'
maxConversationTokens: '100'
maxCompletionTokens: '500'
maxEmbeddingTokens: '8000'
completionsModel: {
name: 'gpt-35-turbo'
version: '0301'
deployment: {
name: 'completions'
}
}
embeddingsModel: {
name: 'text-embedding-ada-002'
version: '2'
deployment: {
name: 'embeddings'
}
}
}
var mongovCoreSettings = {
mongoClusterName: '${name}-mongo'
mongoClusterLogin: mongoDbUserName
mongoClusterPassword: mongoDbPassword
}
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 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 mongoClusterAllowAzure 'Microsoft.DocumentDB/mongoClusters/firewallRules@2023-03-01-preview' = {
parent: mongoCluster
name: 'allowAzure'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
resource mongoClusterAllowAll '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 embeddingsModelDeployment '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 completionsModelDeployment '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'
}
}
dependsOn: [
embeddingsModelDeployment //this is necessary because OpenAI can only deploy one model at a time
]
}
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 functionStorage '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
}
}
}
resource appServiceWebSettings 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appServiceWeb
name: 'appsettings'
kind: 'string'
properties: {
APPINSIGHTS_INSTRUMENTATIONKEY: insightsWeb.properties.InstrumentationKey
OPENAI__ENDPOINT: openAiAccount.properties.endpoint
OPENAI__KEY: openAiAccount.listKeys().key1
OPENAI__EMBEDDINGSDEPLOYMENT: openAiSettings.embeddingsModel.deployment.name
OPENAI__COMPLETIONSDEPLOYMENT: openAiSettings.completionsModel.deployment.name
OPENAI__MAXCONVERSATIONTOKENS: openAiSettings.maxConversationTokens
OPENAI__MAXCOMPLETIONTOKENS: openAiSettings.maxCompletionTokens
OPENAI__MAXEMBEDDINGTOKENS: openAiSettings.maxEmbeddingTokens
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: 'retaildb'
MONGODB__COLLECTIONNAMES: 'product,customer,vectors,completions'
MONGODB__MAXVECTORSEARCHRESULTS: '10'
MONGODB__VECTORINDEXTYPE: 'ivf'
}
dependsOn: [
completionsModelDeployment
embeddingsModelDeployment
]
}
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=${functionStorage.listKeys().keys[0].value}'
APPLICATIONINSIGHTS_CONNECTION_STRING: insightsFunction.properties.ConnectionString
FUNCTIONS_EXTENSION_VERSION: '~4'
FUNCTIONS_WORKER_RUNTIME: 'dotnet-isolated'
OPENAI__ENDPOINT: openAiAccount.properties.endpoint
OPENAI__KEY: openAiAccount.listKeys().key1
OPENAI__EMBEDDINGSDEPLOYMENT: openAiSettings.embeddingsModel.deployment.name
OPENAI__COMPLETIONSDEPLOYMENT: openAiSettings.completionsModel.deployment.name
OPENAI__MAXCONVERSATIONTOKENS: openAiSettings.maxConversationTokens
OPENAI__MAXCOMPLETIONTOKENS: openAiSettings.maxCompletionTokens
OPENAI__MAXEMBEDDINGTOKENS: openAiSettings.maxEmbeddingTokens
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: 'retaildb'
MONGODB__COLLECTIONNAMES: 'product,customer,vectors,completions'
MONGODB__MAXVECTORSEARCHRESULTS: '10'
MONGODB__VECTORINDEXTYPE: 'ivf'
}
dependsOn: [
completionsModelDeployment
embeddingsModelDeployment
]
}
resource appServiceWebSourceControl 'Microsoft.Web/sites/sourcecontrols@2021-03-01' = {
parent: appServiceWeb
name: 'web'
properties: {
repoUrl: appServiceSettings.web.git.repo
branch: appServiceSettings.web.git.branch
isManualIntegration: true
}
}
resource appServiceFunctionSourceControl 'Microsoft.Web/sites/sourcecontrols@2021-03-01' = {
parent: appServiceFunction
name: 'web'
properties: {
repoUrl: appServiceSettings.web.git.repo
branch: appServiceSettings.web.git.branch
isManualIntegration: true
}
}
resource insightsFunction 'Microsoft.Insights/components@2020-02-02' = {
name: appServiceSettings.function.name
location: location
kind: 'web'
properties: {
Application_Type: 'web'
}
}
resource insightsWeb 'Microsoft.Insights/components@2020-02-02' = {
name: appServiceSettings.web.name
location: location
kind: 'web'
properties: {
Application_Type: 'web'
}
}
output deployedUrl string = appServiceWeb.properties.defaultHostName