-
Notifications
You must be signed in to change notification settings - Fork 304
/
main.bicep
1011 lines (913 loc) · 36.6 KB
/
main.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
targetScope = 'subscription'
@minLength(1)
@maxLength(20)
@description('Name of the the environment which is used to generate a short unique hash used in all resources.')
param environmentName string
param resourceToken string = toLower(uniqueString(subscription().id, environmentName, location))
@description('Location for all resources.')
param location string
@description('Name of App Service plan')
param hostingPlanName string = 'hosting-plan-${resourceToken}'
@description('The pricing tier for the App Service plan')
@allowed([
'F1'
'D1'
'B1'
'B2'
'B3'
'S1'
'S2'
'S3'
'P1'
'P2'
'P3'
'P4'
])
param hostingPlanSku string = 'B3'
@description('The sku tier for the App Service plan')
@allowed([
'Free'
'Shared'
'Basic'
'Standard'
'Premium'
'PremiumV2'
'PremiumV3'
])
param skuTier string = 'Basic'
@description('Name of Web App')
param websiteName string = 'web-${resourceToken}'
@description('Name of Admin Web App')
param adminWebsiteName string = '${websiteName}-admin'
@description('Name of Application Insights')
param applicationInsightsName string = 'appinsights-${resourceToken}'
@description('Name of the Workbook')
param workbookDisplayName string = 'workbook-${resourceToken}'
@description('Use semantic search')
param azureSearchUseSemanticSearch string = 'false'
@description('Semantic search config')
param azureSearchSemanticSearchConfig string = 'default'
@description('Is the index prechunked')
param azureSearchIndexIsPrechunked string = 'false'
@description('Top K results')
param azureSearchTopK string = '5'
@description('Enable in domain')
param azureSearchEnableInDomain string = 'false'
@description('Content columns')
param azureSearchContentColumns string = 'content'
@description('Filename column')
param azureSearchFilenameColumn string = 'filename'
@description('Search filter')
param azureSearchFilter string = ''
@description('Title column')
param azureSearchTitleColumn string = 'title'
@description('Url column')
param azureSearchUrlColumn string = 'url'
@description('Use Azure Search Integrated Vectorization (Not yet implemented)')
@allowed([
false
])
param azureSearchUseIntegratedVectorization bool = false
@description('Name of Azure OpenAI Resource')
param azureOpenAIResourceName string = 'openai-${resourceToken}'
@description('Name of Azure OpenAI Resource SKU')
param azureOpenAISkuName string = 'S0'
@description('Azure OpenAI Model Deployment Name')
param azureOpenAIModel string = 'gpt-35-turbo-16k'
@description('Azure OpenAI Model Name')
param azureOpenAIModelName string = 'gpt-35-turbo-16k'
param azureOpenAIModelVersion string = '0613'
@description('Azure OpenAI Model Capacity - See here for more info https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/quota')
param azureOpenAIModelCapacity int = 30
@description('Enables the use of a vision LLM and Computer Vision for embedding images')
param useAdvancedImageProcessing bool = false
@description('Azure OpenAI Vision Model Deployment Name')
param azureOpenAIVisionModel string = 'gpt-4-vision'
@description('Azure OpenAI Vision Model Name')
param azureOpenAIVisionModelName string = 'gpt-4'
@description('Azure OpenAI Vision Model Version')
param azureOpenAIVisionModelVersion string = 'vision-preview'
@description('Azure OpenAI Vision Model Capacity - See here for more info https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/quota')
param azureOpenAIVisionModelCapacity int = 10
@description('Orchestration strategy: openai_function or langchain str. If you use a old version of turbo (0301), plese select langchain')
@allowed([
'openai_function'
'langchain'
])
param orchestrationStrategy string = 'openai_function'
@description('Azure OpenAI Temperature')
param azureOpenAITemperature string = '0'
@description('Azure OpenAI Top P')
param azureOpenAITopP string = '1'
@description('Azure OpenAI Max Tokens')
param azureOpenAIMaxTokens string = '1000'
@description('Azure OpenAI Stop Sequence')
param azureOpenAIStopSequence string = '\n'
@description('Azure OpenAI System Message')
param azureOpenAISystemMessage string = 'You are an AI assistant that helps people find information.'
@description('Azure OpenAI Api Version')
param azureOpenAIApiVersion string = '2024-02-01'
@description('Whether or not to stream responses from Azure OpenAI')
param azureOpenAIStream string = 'true'
@description('Azure OpenAI Embedding Model Deployment Name')
param azureOpenAIEmbeddingModel string = 'text-embedding-ada-002'
@description('Azure OpenAI Embedding Model Name')
param azureOpenAIEmbeddingModelName string = 'text-embedding-ada-002'
@description('Azure OpenAI Embedding Model Capacity - See here for more info https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/quota')
param azureOpenAIEmbeddingModelCapacity int = 30
@description('Name of Computer Vision Resource (if useAdvancedImageProcessing=true)')
param computerVisionName string = 'computer-vision-${resourceToken}'
@description('Name of Computer Vision Resource SKU (if useAdvancedImageProcessing=true)')
@allowed([
'F0'
'S1'
])
param computerVisionSkuName string = 'S1'
@description('Location of Computer Vision Resource (if useAdvancedImageProcessing=true)')
@allowed([// List taken from https://learn.microsoft.com/en-us/azure/ai-services/computer-vision/how-to/image-retrieval?tabs=python#prerequisites
'eastus'
'westus'
'koreacentral'
'francecentral'
'northeurope'
'westeurope'
'southeastasia'
''
])
param computerVisionLocation string = useAdvancedImageProcessing ? location : ''
@description('Azure AI Search Resource')
param azureAISearchName string = 'search-${resourceToken}'
@description('The SKU of the search service you want to create. E.g. free or standard')
@allowed([
'free'
'basic'
'standard'
'standard2'
'standard3'
])
param azureSearchSku string = 'standard'
@description('Azure AI Search Index')
param azureSearchIndex string = 'index-${resourceToken}'
@description('Azure AI Search Indexer')
param azureSearchIndexer string = 'indexer-${resourceToken}'
@description('Azure AI Search Datasource')
param azureSearchDatasource string = 'datasource-${resourceToken}'
@description('Azure AI Search Conversation Log Index')
param azureSearchConversationLogIndex string = 'conversations'
@description('Name of Storage Account')
param storageAccountName string = 'str${resourceToken}'
@description('Name of Function App for Batch document processing')
param functionName string = 'backend-${resourceToken}'
@description('Azure Form Recognizer Name')
param formRecognizerName string = 'formrecog-${resourceToken}'
@description('Azure Content Safety Name')
param contentSafetyName string = 'contentsafety-${resourceToken}'
@description('Azure Speech Service Name')
param speechServiceName string = 'speech-${resourceToken}'
@description('Log Analytics Name')
param logAnalyticsName string = 'la-${resourceToken}'
param newGuidString string = newGuid()
param searchTag string = 'chatwithyourdata-sa'
@description('Whether to use Key Vault to store secrets (best when using keys). If using RBAC, then please set this to false.')
param useKeyVault bool = authType == 'rbac' ? false : true
@description('Id of the user or app to assign application roles')
param principalId string = ''
@description('Whether the Azure services communicate with each other using RBAC or keys. RBAC is recommended, however some users may not have sufficient permissions to assign roles.')
@allowed([
'rbac'
'keys'
])
param authType string = 'keys'
@description('Hosting model for the web apps. Containers are prebuilt and can be deployed faster, but code allows for more customization.')
@allowed([
'code'
'container'
])
param hostingModel string = 'container'
@allowed([
'CRITICAL'
'ERROR'
'WARN'
'INFO'
'DEBUG'
])
param logLevel string = 'INFO'
@description('List of comma-separated languages to recognize from the speech input. Supported languages are listed here: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=stt#supported-languages')
param recognizedLanguages string = 'en-US,fr-FR,de-DE,it-IT'
var blobContainerName = 'documents'
var queueName = 'doc-processing'
var clientKey = '${uniqueString(guid(subscription().id, deployment().name))}${newGuidString}'
var eventGridSystemTopicName = 'doc-processing'
var tags = { 'azd-env-name': environmentName }
var rgName = 'rg-${environmentName}'
var keyVaultName = 'kv-${resourceToken}'
// Organize resources in a resource group
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: rgName
location: location
tags: tags
}
// Store secrets in a keyvault
module keyvault './core/security/keyvault.bicep' = if (useKeyVault || authType == 'rbac') {
name: 'keyvault'
scope: rg
params: {
name: keyVaultName
location: location
tags: tags
principalId: principalId
}
}
var defaultOpenAiDeployments = [
{
name: azureOpenAIModel
model: {
format: 'OpenAI'
name: azureOpenAIModelName
version: azureOpenAIModelVersion
}
sku: {
name: 'Standard'
capacity: azureOpenAIModelCapacity
}
}
{
name: azureOpenAIEmbeddingModel
model: {
format: 'OpenAI'
name: azureOpenAIEmbeddingModelName
version: '2'
}
sku: {
name: 'Standard'
capacity: azureOpenAIEmbeddingModelCapacity
}
}
]
var openAiDeployments = concat(defaultOpenAiDeployments, useAdvancedImageProcessing ? [
{
name: azureOpenAIVisionModel
model: {
format: 'OpenAI'
name: azureOpenAIVisionModelName
version: azureOpenAIVisionModelVersion
}
sku: {
name: 'Standard'
capacity: azureOpenAIVisionModelCapacity
}
}
] : [])
module openai 'core/ai/cognitiveservices.bicep' = {
name: azureOpenAIResourceName
scope: rg
params: {
name: azureOpenAIResourceName
location: location
tags: tags
sku: {
name: azureOpenAISkuName
}
managedIdentity: authType == 'rbac'
deployments: openAiDeployments
}
}
module computerVision 'core/ai/cognitiveservices.bicep' = if (useAdvancedImageProcessing) {
name: 'computerVision'
scope: rg
params: {
name: computerVisionName
kind: 'ComputerVision'
location: computerVisionLocation
tags: tags
sku: {
name: computerVisionSkuName
}
}
}
// Search Index Data Reader
module searchIndexRoleOpenai 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'search-index-role-openai'
params: {
principalId: openai.outputs.identityPrincipalId
roleDefinitionId: '1407120a-92aa-4202-b7e9-c0e197c71c8f'
principalType: 'ServicePrincipal'
}
}
// Search Service Contributor
module searchServiceRoleOpenai 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'search-service-role-openai'
params: {
principalId: openai.outputs.identityPrincipalId
roleDefinitionId: '7ca78c08-252a-4471-8644-bb5ff32d4ba0'
principalType: 'ServicePrincipal'
}
}
// Storage Blob Data Reader
module blobDataReaderRoleSearch 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'blob-data-reader-role-search'
params: {
principalId: search.outputs.identityPrincipalId
roleDefinitionId: '2a2b9908-6ea1-4ae2-8e65-a410df84e7d1'
principalType: 'ServicePrincipal'
}
}
// Cognitive Services OpenAI User
module openAiRoleSearchService 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'openai-role-searchservice'
params: {
principalId: search.outputs.identityPrincipalId
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
principalType: 'ServicePrincipal'
}
}
module speechService 'core/ai/cognitiveservices.bicep' = {
scope: rg
name: speechServiceName
params: {
name: speechServiceName
location: location
sku: {
name: 'S0'
}
kind: 'SpeechServices'
}
}
module storekeys './app/storekeys.bicep' = if (useKeyVault) {
name: 'storekeys'
scope: rg
params: {
keyVaultName: keyVaultName
azureOpenAIName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
formRecognizerName: formrecognizer.outputs.name
contentSafetyName: contentsafety.outputs.name
speechServiceName: speechServiceName
rgName: rgName
}
}
module search './core/search/search-services.bicep' = {
name: azureAISearchName
scope: rg
params: {
name: azureAISearchName
location: location
tags: {
deployment: searchTag
}
sku: {
name: azureSearchSku
}
authOptions: {
aadOrApiKey: {
aadAuthFailureMode: 'http403'
}
}
}
}
module hostingplan './core/host/appserviceplan.bicep' = {
name: hostingPlanName
scope: rg
params: {
name: hostingPlanName
location: location
sku: {
name: hostingPlanSku
tier: skuTier
}
reserved: true
tags: { Automation: 'Ignore' }
}
}
module web './app/web.bicep' = if (hostingModel == 'code') {
name: websiteName
scope: rg
params: {
name: websiteName
location: location
tags: union(tags, { 'azd-service-name': 'web' })
runtimeName: 'python'
runtimeVersion: '3.11'
appServicePlanId: hostingplan.outputs.name
applicationInsightsName: monitoring.outputs.applicationInsightsName
healthCheckPath: '/api/health'
azureOpenAIName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
formRecognizerName: formrecognizer.outputs.name
contentSafetyName: contentsafety.outputs.name
speechServiceName: speechService.outputs.name
openAIKeyName: useKeyVault ? storekeys.outputs.OPENAI_KEY_NAME : ''
storageAccountKeyName: useKeyVault ? storekeys.outputs.STORAGE_ACCOUNT_KEY_NAME : ''
formRecognizerKeyName: useKeyVault ? storekeys.outputs.FORM_RECOGNIZER_KEY_NAME : ''
searchKeyName: useKeyVault ? storekeys.outputs.SEARCH_KEY_NAME : ''
contentSafetyKeyName: useKeyVault ? storekeys.outputs.CONTENT_SAFETY_KEY_NAME : ''
speechKeyName: useKeyVault ? storekeys.outputs.SPEECH_KEY_NAME : ''
useKeyVault: useKeyVault
keyVaultName: useKeyVault || authType == 'rbac' ? keyvault.outputs.name : ''
authType: authType
appSettings: {
AZURE_BLOB_ACCOUNT_NAME: storageAccountName
AZURE_BLOB_CONTAINER_NAME: blobContainerName
AZURE_CONTENT_SAFETY_ENDPOINT: contentsafety.outputs.endpoint
AZURE_FORM_RECOGNIZER_ENDPOINT: formrecognizer.outputs.endpoint
AZURE_OPENAI_RESOURCE: azureOpenAIResourceName
AZURE_OPENAI_MODEL: azureOpenAIModel
AZURE_OPENAI_MODEL_NAME: azureOpenAIModelName
AZURE_OPENAI_TEMPERATURE: azureOpenAITemperature
AZURE_OPENAI_TOP_P: azureOpenAITopP
AZURE_OPENAI_MAX_TOKENS: azureOpenAIMaxTokens
AZURE_OPENAI_STOP_SEQUENCE: azureOpenAIStopSequence
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
AZURE_OPENAI_API_VERSION: azureOpenAIApiVersion
AZURE_OPENAI_STREAM: azureOpenAIStream
AZURE_OPENAI_EMBEDDING_MODEL: azureOpenAIEmbeddingModel
AZURE_SEARCH_USE_SEMANTIC_SEARCH: azureSearchUseSemanticSearch
AZURE_SEARCH_SERVICE: 'https://${azureAISearchName}.search.windows.net'
AZURE_SEARCH_INDEX: azureSearchIndex
AZURE_SEARCH_CONVERSATIONS_LOG_INDEX: azureSearchConversationLogIndex
AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG: azureSearchSemanticSearchConfig
AZURE_SEARCH_INDEX_IS_PRECHUNKED: azureSearchIndexIsPrechunked
AZURE_SEARCH_TOP_K: azureSearchTopK
AZURE_SEARCH_ENABLE_IN_DOMAIN: azureSearchEnableInDomain
AZURE_SEARCH_CONTENT_COLUMNS: azureSearchContentColumns
AZURE_SEARCH_FILENAME_COLUMN: azureSearchFilenameColumn
AZURE_SEARCH_FILTER: azureSearchFilter
AZURE_SEARCH_TITLE_COLUMN: azureSearchTitleColumn
AZURE_SEARCH_URL_COLUMN: azureSearchUrlColumn
AZURE_SPEECH_SERVICE_NAME: speechServiceName
AZURE_SPEECH_SERVICE_REGION: location
AZURE_SPEECH_RECOGNIZER_LANGUAGES: recognizedLanguages
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
}
}
}
module web_docker './app/web.bicep' = if (hostingModel == 'container') {
name: '${websiteName}-docker'
scope: rg
params: {
name: '${websiteName}-docker'
location: location
tags: union(tags, { 'azd-service-name': 'web-docker' })
dockerFullImageName: 'fruoccopublic.azurecr.io/rag-webapp'
appServicePlanId: hostingplan.outputs.name
applicationInsightsName: monitoring.outputs.applicationInsightsName
healthCheckPath: '/api/health'
azureOpenAIName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
formRecognizerName: formrecognizer.outputs.name
contentSafetyName: contentsafety.outputs.name
speechServiceName: speechService.outputs.name
openAIKeyName: useKeyVault ? storekeys.outputs.OPENAI_KEY_NAME : ''
storageAccountKeyName: useKeyVault ? storekeys.outputs.STORAGE_ACCOUNT_KEY_NAME : ''
formRecognizerKeyName: useKeyVault ? storekeys.outputs.FORM_RECOGNIZER_KEY_NAME : ''
searchKeyName: useKeyVault ? storekeys.outputs.SEARCH_KEY_NAME : ''
contentSafetyKeyName: useKeyVault ? storekeys.outputs.CONTENT_SAFETY_KEY_NAME : ''
speechKeyName: useKeyVault ? storekeys.outputs.SPEECH_KEY_NAME : ''
useKeyVault: useKeyVault
keyVaultName: useKeyVault || authType == 'rbac' ? keyvault.outputs.name : ''
authType: authType
appSettings: {
AZURE_BLOB_ACCOUNT_NAME: storageAccountName
AZURE_BLOB_CONTAINER_NAME: blobContainerName
AZURE_CONTENT_SAFETY_ENDPOINT: contentsafety.outputs.endpoint
AZURE_FORM_RECOGNIZER_ENDPOINT: formrecognizer.outputs.endpoint
AZURE_OPENAI_RESOURCE: azureOpenAIResourceName
AZURE_OPENAI_MODEL: azureOpenAIModel
AZURE_OPENAI_MODEL_NAME: azureOpenAIModelName
AZURE_OPENAI_TEMPERATURE: azureOpenAITemperature
AZURE_OPENAI_TOP_P: azureOpenAITopP
AZURE_OPENAI_MAX_TOKENS: azureOpenAIMaxTokens
AZURE_OPENAI_STOP_SEQUENCE: azureOpenAIStopSequence
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
AZURE_OPENAI_API_VERSION: azureOpenAIApiVersion
AZURE_OPENAI_STREAM: azureOpenAIStream
AZURE_OPENAI_EMBEDDING_MODEL: azureOpenAIEmbeddingModel
AZURE_SEARCH_USE_SEMANTIC_SEARCH: azureSearchUseSemanticSearch
AZURE_SEARCH_SERVICE: 'https://${azureAISearchName}.search.windows.net'
AZURE_SEARCH_INDEX: azureSearchIndex
AZURE_SEARCH_CONVERSATIONS_LOG_INDEX: azureSearchConversationLogIndex
AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG: azureSearchSemanticSearchConfig
AZURE_SEARCH_INDEX_IS_PRECHUNKED: azureSearchIndexIsPrechunked
AZURE_SEARCH_TOP_K: azureSearchTopK
AZURE_SEARCH_ENABLE_IN_DOMAIN: azureSearchEnableInDomain
AZURE_SEARCH_CONTENT_COLUMNS: azureSearchContentColumns
AZURE_SEARCH_FILENAME_COLUMN: azureSearchFilenameColumn
AZURE_SEARCH_FILTER: azureSearchFilter
AZURE_SEARCH_TITLE_COLUMN: azureSearchTitleColumn
AZURE_SEARCH_URL_COLUMN: azureSearchUrlColumn
AZURE_SPEECH_SERVICE_NAME: speechServiceName
AZURE_SPEECH_SERVICE_REGION: location
AZURE_SPEECH_RECOGNIZER_LANGUAGES: recognizedLanguages
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
}
}
}
module adminweb './app/adminweb.bicep' = if (hostingModel == 'code') {
name: adminWebsiteName
scope: rg
params: {
name: adminWebsiteName
location: location
tags: union(tags, { 'azd-service-name': 'adminweb' })
runtimeName: 'python'
runtimeVersion: '3.11'
appServicePlanId: hostingplan.outputs.name
applicationInsightsName: monitoring.outputs.applicationInsightsName
azureOpenAIName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
formRecognizerName: formrecognizer.outputs.name
contentSafetyName: contentsafety.outputs.name
speechServiceName: speechService.outputs.name
openAIKeyName: useKeyVault ? storekeys.outputs.OPENAI_KEY_NAME : ''
storageAccountKeyName: useKeyVault ? storekeys.outputs.STORAGE_ACCOUNT_KEY_NAME : ''
formRecognizerKeyName: useKeyVault ? storekeys.outputs.FORM_RECOGNIZER_KEY_NAME : ''
searchKeyName: useKeyVault ? storekeys.outputs.SEARCH_KEY_NAME : ''
contentSafetyKeyName: useKeyVault ? storekeys.outputs.CONTENT_SAFETY_KEY_NAME : ''
speechKeyName: useKeyVault ? storekeys.outputs.SPEECH_KEY_NAME : ''
useKeyVault: useKeyVault
keyVaultName: useKeyVault || authType == 'rbac' ? keyvault.outputs.name : ''
authType: authType
appSettings: {
AZURE_BLOB_ACCOUNT_NAME: storageAccountName
AZURE_BLOB_CONTAINER_NAME: blobContainerName
AZURE_CONTENT_SAFETY_ENDPOINT: contentsafety.outputs.endpoint
AZURE_FORM_RECOGNIZER_ENDPOINT: formrecognizer.outputs.endpoint
AZURE_OPENAI_RESOURCE: azureOpenAIResourceName
AZURE_OPENAI_MODEL: azureOpenAIModel
AZURE_OPENAI_MODEL_NAME: azureOpenAIModelName
AZURE_OPENAI_TEMPERATURE: azureOpenAITemperature
AZURE_OPENAI_TOP_P: azureOpenAITopP
AZURE_OPENAI_MAX_TOKENS: azureOpenAIMaxTokens
AZURE_OPENAI_STOP_SEQUENCE: azureOpenAIStopSequence
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
AZURE_OPENAI_API_VERSION: azureOpenAIApiVersion
AZURE_OPENAI_STREAM: azureOpenAIStream
AZURE_OPENAI_EMBEDDING_MODEL: azureOpenAIEmbeddingModel
AZURE_SEARCH_SERVICE: 'https://${azureAISearchName}.search.windows.net'
AZURE_SEARCH_INDEX: azureSearchIndex
AZURE_SEARCH_USE_SEMANTIC_SEARCH: azureSearchUseSemanticSearch
AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG: azureSearchSemanticSearchConfig
AZURE_SEARCH_INDEX_IS_PRECHUNKED: azureSearchIndexIsPrechunked
AZURE_SEARCH_TOP_K: azureSearchTopK
AZURE_SEARCH_ENABLE_IN_DOMAIN: azureSearchEnableInDomain
AZURE_SEARCH_CONTENT_COLUMNS: azureSearchContentColumns
AZURE_SEARCH_FILENAME_COLUMN: azureSearchFilenameColumn
AZURE_SEARCH_FILTER: azureSearchFilter
AZURE_SEARCH_TITLE_COLUMN: azureSearchTitleColumn
AZURE_SEARCH_URL_COLUMN: azureSearchUrlColumn
BACKEND_URL: 'https://${functionName}.azurewebsites.net'
DOCUMENT_PROCESSING_QUEUE_NAME: queueName
FUNCTION_KEY: clientKey
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
}
}
}
module adminweb_docker './app/adminweb.bicep' = if (hostingModel == 'container') {
name: '${adminWebsiteName}-docker'
scope: rg
params: {
name: '${adminWebsiteName}-docker'
location: location
tags: union(tags, { 'azd-service-name': 'adminweb-docker' })
dockerFullImageName: 'fruoccopublic.azurecr.io/rag-adminwebapp'
appServicePlanId: hostingplan.outputs.name
applicationInsightsName: monitoring.outputs.applicationInsightsName
azureOpenAIName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
formRecognizerName: formrecognizer.outputs.name
contentSafetyName: contentsafety.outputs.name
speechServiceName: speechService.outputs.name
openAIKeyName: useKeyVault ? storekeys.outputs.OPENAI_KEY_NAME : ''
storageAccountKeyName: useKeyVault ? storekeys.outputs.STORAGE_ACCOUNT_KEY_NAME : ''
formRecognizerKeyName: useKeyVault ? storekeys.outputs.FORM_RECOGNIZER_KEY_NAME : ''
searchKeyName: useKeyVault ? storekeys.outputs.SEARCH_KEY_NAME : ''
contentSafetyKeyName: useKeyVault ? storekeys.outputs.CONTENT_SAFETY_KEY_NAME : ''
speechKeyName: useKeyVault ? storekeys.outputs.SPEECH_KEY_NAME : ''
useKeyVault: useKeyVault
keyVaultName: useKeyVault || authType == 'rbac' ? keyvault.outputs.name : ''
authType: authType
appSettings: {
AZURE_BLOB_ACCOUNT_NAME: storageAccountName
AZURE_BLOB_CONTAINER_NAME: blobContainerName
AZURE_CONTENT_SAFETY_ENDPOINT: contentsafety.outputs.endpoint
AZURE_FORM_RECOGNIZER_ENDPOINT: formrecognizer.outputs.endpoint
AZURE_OPENAI_RESOURCE: azureOpenAIResourceName
AZURE_OPENAI_MODEL: azureOpenAIModel
AZURE_OPENAI_MODEL_NAME: azureOpenAIModelName
AZURE_OPENAI_TEMPERATURE: azureOpenAITemperature
AZURE_OPENAI_TOP_P: azureOpenAITopP
AZURE_OPENAI_MAX_TOKENS: azureOpenAIMaxTokens
AZURE_OPENAI_STOP_SEQUENCE: azureOpenAIStopSequence
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
AZURE_OPENAI_API_VERSION: azureOpenAIApiVersion
AZURE_OPENAI_STREAM: azureOpenAIStream
AZURE_OPENAI_EMBEDDING_MODEL: azureOpenAIEmbeddingModel
AZURE_SEARCH_SERVICE: 'https://${azureAISearchName}.search.windows.net'
AZURE_SEARCH_INDEX: azureSearchIndex
AZURE_SEARCH_USE_SEMANTIC_SEARCH: azureSearchUseSemanticSearch
AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG: azureSearchSemanticSearchConfig
AZURE_SEARCH_INDEX_IS_PRECHUNKED: azureSearchIndexIsPrechunked
AZURE_SEARCH_TOP_K: azureSearchTopK
AZURE_SEARCH_ENABLE_IN_DOMAIN: azureSearchEnableInDomain
AZURE_SEARCH_CONTENT_COLUMNS: azureSearchContentColumns
AZURE_SEARCH_FILENAME_COLUMN: azureSearchFilenameColumn
AZURE_SEARCH_FILTER: azureSearchFilter
AZURE_SEARCH_TITLE_COLUMN: azureSearchTitleColumn
AZURE_SEARCH_URL_COLUMN: azureSearchUrlColumn
BACKEND_URL: 'https://${functionName}-docker.azurewebsites.net'
DOCUMENT_PROCESSING_QUEUE_NAME: queueName
FUNCTION_KEY: clientKey
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
}
}
}
module monitoring './core/monitor/monitoring.bicep' = {
name: 'monitoring'
scope: rg
params: {
applicationInsightsName: applicationInsightsName
location: location
tags: {
'hidden-link:${resourceId('Microsoft.Web/sites', applicationInsightsName)}': 'Resource'
}
logAnalyticsName: logAnalyticsName
applicationInsightsDashboardName: 'dash-${applicationInsightsName}'
}
}
module workbook './app/workbook.bicep' = {
name: 'workbook'
scope: rg
params: {
workbookDisplayName: workbookDisplayName
location: location
hostingPlanName: hostingplan.outputs.name
functionName: hostingModel == 'container' ? function_docker.outputs.functionName : function.outputs.functionName
websiteName: hostingModel == 'container' ? web_docker.outputs.FRONTEND_API_NAME : web.outputs.FRONTEND_API_NAME
adminWebsiteName: hostingModel == 'container' ? adminweb_docker.outputs.WEBSITE_ADMIN_NAME : adminweb.outputs.WEBSITE_ADMIN_NAME
eventGridSystemTopicName: eventgrid.outputs.name
logAnalyticsName: monitoring.outputs.logAnalyticsWorkspaceName
azureOpenAIResourceName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
}
}
module function './app/function.bicep' = if (hostingModel == 'code') {
name: functionName
scope: rg
params: {
name: functionName
location: location
tags: union(tags, { 'azd-service-name': 'function' })
runtimeName: 'python'
runtimeVersion: '3.11'
appServicePlanId: hostingplan.outputs.name
applicationInsightsName: monitoring.outputs.applicationInsightsName
azureOpenAIName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
formRecognizerName: formrecognizer.outputs.name
contentSafetyName: contentsafety.outputs.name
speechServiceName: speechService.outputs.name
clientKey: clientKey
openAIKeyName: useKeyVault ? storekeys.outputs.OPENAI_KEY_NAME : ''
storageAccountKeyName: useKeyVault ? storekeys.outputs.STORAGE_ACCOUNT_KEY_NAME : ''
formRecognizerKeyName: useKeyVault ? storekeys.outputs.FORM_RECOGNIZER_KEY_NAME : ''
searchKeyName: useKeyVault ? storekeys.outputs.SEARCH_KEY_NAME : ''
contentSafetyKeyName: useKeyVault ? storekeys.outputs.CONTENT_SAFETY_KEY_NAME : ''
speechKeyName: useKeyVault ? storekeys.outputs.SPEECH_KEY_NAME : ''
useKeyVault: useKeyVault
keyVaultName: useKeyVault || authType == 'rbac' ? keyvault.outputs.name : ''
authType: authType
appSettings: {
AZURE_BLOB_ACCOUNT_NAME: storageAccountName
AZURE_BLOB_CONTAINER_NAME: blobContainerName
AZURE_CONTENT_SAFETY_ENDPOINT: contentsafety.outputs.endpoint
AZURE_FORM_RECOGNIZER_ENDPOINT: formrecognizer.outputs.endpoint
AZURE_OPENAI_MODEL: azureOpenAIModel
AZURE_OPENAI_EMBEDDING_MODEL: azureOpenAIEmbeddingModel
AZURE_OPENAI_RESOURCE: azureOpenAIResourceName
AZURE_OPENAI_API_VERSION: azureOpenAIApiVersion
AZURE_SEARCH_INDEX: azureSearchIndex
AZURE_SEARCH_SERVICE: 'https://${azureAISearchName}.search.windows.net'
DOCUMENT_PROCESSING_QUEUE_NAME: queueName
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
}
}
}
module function_docker './app/function.bicep' = if (hostingModel == 'container') {
name: '${functionName}-docker'
scope: rg
params: {
name: '${functionName}-docker'
location: location
tags: union(tags, { 'azd-service-name': 'function-docker' })
dockerFullImageName: 'fruoccopublic.azurecr.io/rag-backend'
appServicePlanId: hostingplan.outputs.name
applicationInsightsName: monitoring.outputs.applicationInsightsName
azureOpenAIName: openai.outputs.name
azureAISearchName: search.outputs.name
storageAccountName: storage.outputs.name
formRecognizerName: formrecognizer.outputs.name
contentSafetyName: contentsafety.outputs.name
speechServiceName: speechService.outputs.name
clientKey: clientKey
openAIKeyName: useKeyVault ? storekeys.outputs.OPENAI_KEY_NAME : ''
storageAccountKeyName: useKeyVault ? storekeys.outputs.STORAGE_ACCOUNT_KEY_NAME : ''
formRecognizerKeyName: useKeyVault ? storekeys.outputs.FORM_RECOGNIZER_KEY_NAME : ''
searchKeyName: useKeyVault ? storekeys.outputs.SEARCH_KEY_NAME : ''
contentSafetyKeyName: useKeyVault ? storekeys.outputs.CONTENT_SAFETY_KEY_NAME : ''
speechKeyName: useKeyVault ? storekeys.outputs.SPEECH_KEY_NAME : ''
useKeyVault: useKeyVault
keyVaultName: useKeyVault || authType == 'rbac' ? keyvault.outputs.name : ''
authType: authType
appSettings: {
AZURE_BLOB_ACCOUNT_NAME: storageAccountName
AZURE_BLOB_CONTAINER_NAME: blobContainerName
AZURE_CONTENT_SAFETY_ENDPOINT: contentsafety.outputs.endpoint
AZURE_FORM_RECOGNIZER_ENDPOINT: formrecognizer.outputs.endpoint
AZURE_OPENAI_MODEL: azureOpenAIModel
AZURE_OPENAI_EMBEDDING_MODEL: azureOpenAIEmbeddingModel
AZURE_OPENAI_RESOURCE: azureOpenAIResourceName
AZURE_OPENAI_API_VERSION: azureOpenAIApiVersion
AZURE_SEARCH_INDEX: azureSearchIndex
AZURE_SEARCH_SERVICE: 'https://${azureAISearchName}.search.windows.net'
DOCUMENT_PROCESSING_QUEUE_NAME: queueName
ORCHESTRATION_STRATEGY: orchestrationStrategy
LOGLEVEL: logLevel
}
}
}
module formrecognizer 'core/ai/cognitiveservices.bicep' = {
name: formRecognizerName
scope: rg
params: {
name: formRecognizerName
location: location
tags: tags
kind: 'FormRecognizer'
}
}
module contentsafety 'core/ai/cognitiveservices.bicep' = {
name: contentSafetyName
scope: rg
params: {
name: contentSafetyName
location: location
tags: tags
kind: 'ContentSafety'
}
}
module eventgrid 'app/eventgrid.bicep' = {
name: eventGridSystemTopicName
scope: rg
params: {
name: eventGridSystemTopicName
location: location
storageAccountId: storage.outputs.id
queueName: queueName
blobContainerName: blobContainerName
}
}
module storage 'core/storage/storage-account.bicep' = {
name: storageAccountName
scope: rg
params: {
name: storageAccountName
location: location
sku: {
name: 'Standard_GRS'
}
deleteRetentionPolicy: azureSearchUseIntegratedVectorization ? {
enabled: true
days: 7
} : {}
containers: [
{
name: blobContainerName
publicAccess: 'None'
}
{
name: 'config'
publicAccess: 'None'
}
]
queues: [
{
name: 'doc-processing'
}
{
name: 'doc-processing-poison'
}
]
}
}
// USER ROLES
// Storage Blob Data Contributor
module storageRoleUser 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'storage-role-user'
params: {
principalId: principalId
roleDefinitionId: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
principalType: 'User'
}
}
// Cognitive Services User
module openaiRoleUser 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'openai-role-user'
params: {
principalId: principalId
roleDefinitionId: 'a97b65f3-24c7-4388-baec-2e87135dc908'
principalType: 'User'
}
}
// Contributor
module openaiRoleUserContributor 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'openai-role-user-contributor'
params: {
principalId: principalId
roleDefinitionId: 'b24988ac-6180-42a0-ab88-20f7382dd24c'
principalType: 'User'
}
}
// Search Index Data Contributor
module searchRoleUser 'core/security/role.bicep' = if (authType == 'rbac') {
scope: rg
name: 'search-role-user'
params: {
principalId: principalId
roleDefinitionId: '8ebe5a00-799e-43f5-93ac-243d3dce84a7'
principalType: 'User'
}
}
// TODO: Streamline to one key=value pair
output APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
output APPINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
output APPINSIGHTS_INSTRUMENTATIONKEY string = monitoring.outputs.applicationInsightsInstrumentationKey
output AZURE_BLOB_CONTAINER_NAME string = blobContainerName
output AZURE_BLOB_ACCOUNT_NAME string = storageAccountName
output AZURE_BLOB_ACCOUNT_KEY string = useKeyVault ? storekeys.outputs.STORAGE_ACCOUNT_KEY_NAME : ''
output AZURE_CONTENT_SAFETY_ENDPOINT string = contentsafety.outputs.endpoint
output AZURE_CONTENT_SAFETY_KEY string = useKeyVault ? storekeys.outputs.CONTENT_SAFETY_KEY_NAME : ''
output AZURE_FORM_RECOGNIZER_ENDPOINT string = formrecognizer.outputs.endpoint
output AZURE_FORM_RECOGNIZER_KEY string = useKeyVault ? storekeys.outputs.FORM_RECOGNIZER_KEY_NAME : ''
output AZURE_KEY_VAULT_ENDPOINT string = useKeyVault ? keyvault.outputs.endpoint : ''
output AZURE_KEY_VAULT_NAME string = useKeyVault || authType == 'rbac' ? keyvault.outputs.name : ''
output AZURE_LOCATION string = location
output AZURE_OPENAI_MODEL_NAME string = azureOpenAIModelName
output AZURE_OPENAI_STREAM string = azureOpenAIStream
output AZURE_OPENAI_SYSTEM_MESSAGE string = azureOpenAISystemMessage
output AZURE_OPENAI_STOP_SEQUENCE string = azureOpenAIStopSequence
output AZURE_OPENAI_MAX_TOKENS string = azureOpenAIMaxTokens
output AZURE_OPENAI_TOP_P string = azureOpenAITopP
output AZURE_OPENAI_TEMPERATURE string = azureOpenAITemperature
output AZURE_OPENAI_API_VERSION string = azureOpenAIApiVersion
output AZURE_OPENAI_RESOURCE string = azureOpenAIResourceName
output AZURE_OPENAI_EMBEDDING_MODEL string = azureOpenAIEmbeddingModel
output AZURE_OPENAI_MODEL string = azureOpenAIModel
output AZURE_OPENAI_API_KEY string = useKeyVault ? storekeys.outputs.OPENAI_KEY_NAME : ''
output AZURE_RESOURCE_GROUP string = rgName
output AZURE_SEARCH_KEY string = useKeyVault ? storekeys.outputs.SEARCH_KEY_NAME : ''
output AZURE_SEARCH_SERVICE string = search.outputs.endpoint
output AZURE_SEARCH_USE_SEMANTIC_SEARCH string = azureSearchUseSemanticSearch
output AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG string = azureSearchSemanticSearchConfig
output AZURE_SEARCH_INDEX_IS_PRECHUNKED string = azureSearchIndexIsPrechunked
output AZURE_SEARCH_TOP_K string = azureSearchTopK
output AZURE_SEARCH_ENABLE_IN_DOMAIN string = azureSearchEnableInDomain
output AZURE_SEARCH_CONTENT_COLUMNS string = azureSearchContentColumns
output AZURE_SEARCH_FILENAME_COLUMN string = azureSearchFilenameColumn
output AZURE_SEARCH_FILTER string = azureSearchFilter
output AZURE_SEARCH_TITLE_COLUMN string = azureSearchTitleColumn
output AZURE_SEARCH_URL_COLUMN string = azureSearchUrlColumn
output AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION bool = azureSearchUseIntegratedVectorization
output AZURE_SEARCH_INDEX string = azureSearchIndex
output AZURE_SEARCH_INDEXER_NAME string = azureSearchIndexer
output AZURE_SEARCH_DATASOURCE_NAME string = azureSearchDatasource
output AZURE_SPEECH_SERVICE_NAME string = speechServiceName