@@ -32,7 +32,7 @@ param principalId string = ''
32
32
param openAILocation string
33
33
34
34
@description ('Name of the OpenAI resource group. If not specified, the resource group name will be generated.' )
35
- param openAiResourceGroupName string = ''
35
+ param openAIResourceGroupName string = ''
36
36
37
37
@description ('Whether to deploy Azure OpenAI resources' )
38
38
param deployAzureOpenAI bool = true
@@ -47,15 +47,22 @@ param chatDeploymentName string = ''
47
47
// https://learn.microsoft.com/azure/ai-services/openai/concepts/models#gpt-4-and-gpt-4-turbo-preview-models
48
48
param chatDeploymentVersion string = ''
49
49
50
- param azureOpenAiAPIVersion string = '2024-03-01-preview'
50
+ param azureOpenAIAPIVersion string = '2024-03-01-preview'
51
+ @secure ()
52
+ param azureOpenAIKey string = ''
53
+ @description ('Azure OpenAI endpoint to use, if not using the one deployed here.' )
54
+ param azureOpenAIEndpoint string = ''
55
+
56
+ @description ('Whether to use Azure OpenAI (either deployed here or elsewhere) or OpenAI.com' )
57
+ var useAzureOpenAI = deployAzureOpenAI || !empty (azureOpenAIEndpoint )
51
58
52
59
@description ('Capacity of the GPT deployment' )
53
60
// You can increase this, but capacity is limited per model/region, so you will get errors if you go over
54
61
// https://learn.microsoft.com/en-us/azure/ai-services/openai/quotas-limits
55
62
param chatDeploymentCapacity int = 0
56
63
var chatConfig = {
57
- modelName : !empty (chatModelName ) ? chatModelName : deployAzureOpenAI ? 'gpt-35-turbo' : 'gpt-3.5-turbo'
58
- deploymentName : !empty (chatDeploymentName ) ? chatDeploymentName : 'chat '
64
+ modelName : !empty (chatModelName ) ? chatModelName : ( useAzureOpenAI ? 'gpt-35-turbo' : 'gpt-3.5-turbo' )
65
+ deploymentName : !empty (chatDeploymentName ) ? chatDeploymentName : 'gpt-35-turbo '
59
66
deploymentVersion : !empty (chatDeploymentVersion ) ? chatDeploymentVersion : '0125'
60
67
deploymentCapacity : chatDeploymentCapacity != 0 ? chatDeploymentCapacity : 30
61
68
}
@@ -68,7 +75,7 @@ param embedDimensions int = 0
68
75
69
76
var embedConfig = {
70
77
modelName : !empty (embedModelName ) ? embedModelName : 'text-embedding-ada-002'
71
- deploymentName : !empty (embedDeploymentName ) ? embedDeploymentName : 'embed '
78
+ deploymentName : !empty (embedDeploymentName ) ? embedDeploymentName : 'text-embedding-ada-002 '
72
79
deploymentVersion : !empty (embedDeploymentVersion ) ? embedDeploymentVersion : '2'
73
80
deploymentCapacity : embedDeploymentCapacity != 0 ? embedDeploymentCapacity : 30
74
81
dimensions : embedDimensions != 0 ? embedDimensions : 1536
@@ -145,6 +152,91 @@ module containerApps 'core/host/container-apps.bicep' = {
145
152
// Web frontend
146
153
var webAppName = replace ('${take (prefix , 19 )}-ca' , '--' , '-' )
147
154
var webAppIdentityName = '${prefix }-id-web'
155
+ var webAppEnv = [
156
+ {
157
+ name : 'POSTGRES_HOST'
158
+ value : postgresServer .outputs .POSTGRES_DOMAIN_NAME
159
+ }
160
+ {
161
+ name : 'POSTGRES_USERNAME'
162
+ value : webAppIdentityName
163
+ }
164
+ {
165
+ name : 'POSTGRES_DATABASE'
166
+ value : postgresDatabaseName
167
+ }
168
+ {
169
+ name : 'POSTGRES_SSL'
170
+ value : 'require'
171
+ }
172
+ {
173
+ name : 'RUNNING_IN_PRODUCTION'
174
+ value : 'true'
175
+ }
176
+ {
177
+ name : 'APPLICATIONINSIGHTS_CONNECTION_STRING'
178
+ value : monitoring .outputs .applicationInsightsConnectionString
179
+ }
180
+ {
181
+ name : 'OPENAI_CHAT_HOST'
182
+ value : useAzureOpenAI ? 'azure' : 'openaicom'
183
+ }
184
+ {
185
+ name : 'AZURE_OPENAI_CHAT_DEPLOYMENT'
186
+ value : useAzureOpenAI ? chatConfig .deploymentName : ''
187
+ }
188
+ {
189
+ name : 'AZURE_OPENAI_CHAT_MODEL'
190
+ value : useAzureOpenAI ? chatConfig .modelName : ''
191
+ }
192
+ {
193
+ name : 'OPENAICOM_CHAT_MODEL'
194
+ value : useAzureOpenAI ? '' : 'gpt-3.5-turbo'
195
+ }
196
+ {
197
+ name : 'OPENAI_EMBED_HOST'
198
+ value : useAzureOpenAI ? 'azure' : 'openaicom'
199
+ }
200
+ {
201
+ name : 'OPENAICOM_EMBED_MODEL_DIMENSIONS'
202
+ value : useAzureOpenAI ? '' : '1536'
203
+ }
204
+ {
205
+ name : 'OPENAICOM_EMBED_MODEL'
206
+ value : useAzureOpenAI ? '' : 'text-embedding-ada-002'
207
+ }
208
+ {
209
+ name : 'AZURE_OPENAI_EMBED_MODEL'
210
+ value : useAzureOpenAI ? embedConfig .modelName : ''
211
+ }
212
+ {
213
+ name : 'AZURE_OPENAI_EMBED_DEPLOYMENT'
214
+ value : useAzureOpenAI ? embedConfig .deploymentName : ''
215
+ }
216
+ {
217
+ name : 'AZURE_OPENAI_EMBED_MODEL_DIMENSIONS'
218
+ value : useAzureOpenAI ? string (embedConfig .dimensions ) : ''
219
+ }
220
+ {
221
+ name : 'AZURE_OPENAI_ENDPOINT'
222
+ value : useAzureOpenAI ? (deployAzureOpenAI ? openAI .outputs .endpoint : azureOpenAIEndpoint ) : ''
223
+ }
224
+ {
225
+ name : 'AZURE_OPENAI_VERSION'
226
+ value : useAzureOpenAI ? azureOpenAIAPIVersion : ''
227
+ }
228
+ ]
229
+ var webAppEnvWithSecret = !empty (azureOpenAIKey ) ? union (webAppEnv , [
230
+ {
231
+ name : 'AZURE_OPENAI_KEY'
232
+ secretRef : 'azure-openai-key'
233
+ }
234
+ ]) : webAppEnv
235
+
236
+ var secrets = !empty (azureOpenAIKey ) ? {
237
+ 'azure-openai-key' : azureOpenAIKey
238
+ } : {}
239
+
148
240
module web 'web.bicep' = {
149
241
name : 'web'
150
242
scope : resourceGroup
@@ -156,91 +248,19 @@ module web 'web.bicep' = {
156
248
containerAppsEnvironmentName : containerApps .outputs .environmentName
157
249
containerRegistryName : containerApps .outputs .registryName
158
250
exists : webAppExists
159
- environmentVariables : [
160
- {
161
- name : 'POSTGRES_HOST'
162
- value : postgresServer .outputs .POSTGRES_DOMAIN_NAME
163
- }
164
- {
165
- name : 'POSTGRES_USERNAME'
166
- value : webAppIdentityName
167
- }
168
- {
169
- name : 'POSTGRES_DATABASE'
170
- value : postgresDatabaseName
171
- }
172
- {
173
- name : 'POSTGRES_SSL'
174
- value : 'require'
175
- }
176
- {
177
- name : 'RUNNING_IN_PRODUCTION'
178
- value : 'true'
179
- }
180
- {
181
- name : 'APPLICATIONINSIGHTS_CONNECTION_STRING'
182
- value : monitoring .outputs .applicationInsightsConnectionString
183
- }
184
- {
185
- name : 'OPENAI_CHAT_HOST'
186
- value : deployAzureOpenAI ? 'azure' : 'openaicom'
187
- }
188
- {
189
- name : 'AZURE_OPENAI_CHAT_DEPLOYMENT'
190
- value : deployAzureOpenAI ? chatConfig .deploymentName : ''
191
- }
192
- {
193
- name : 'AZURE_OPENAI_CHAT_MODEL'
194
- value : deployAzureOpenAI ? chatConfig .modelName : ''
195
- }
196
- {
197
- name : 'OPENAICOM_CHAT_MODEL'
198
- value : deployAzureOpenAI ? '' : 'gpt-3.5-turbo'
199
- }
200
- {
201
- name : 'OPENAI_EMBED_HOST'
202
- value : deployAzureOpenAI ? 'azure' : 'openaicom'
203
- }
204
- {
205
- name : 'OPENAICOM_EMBED_MODEL_DIMENSIONS'
206
- value : deployAzureOpenAI ? '' : '1536'
207
- }
208
- {
209
- name : 'OPENAICOM_EMBED_MODEL'
210
- value : deployAzureOpenAI ? '' : 'text-embedding-ada-002'
211
- }
212
- {
213
- name : 'AZURE_OPENAI_EMBED_MODEL'
214
- value : deployAzureOpenAI ? embedConfig .modelName : ''
215
- }
216
- {
217
- name : 'AZURE_OPENAI_EMBED_DEPLOYMENT'
218
- value : deployAzureOpenAI ? embedConfig .deploymentName : ''
219
- }
220
- {
221
- name : 'AZURE_OPENAI_EMBED_MODEL_DIMENSIONS'
222
- value : deployAzureOpenAI ? string (embedConfig .dimensions ) : ''
223
- }
224
- {
225
- name : 'AZURE_OPENAI_ENDPOINT'
226
- value : deployAzureOpenAI ? openAi .outputs .endpoint : ''
227
- }
228
- {
229
- name : 'AZURE_OPENAI_VERSION'
230
- value : deployAzureOpenAI ? azureOpenAiAPIVersion : ''
231
- }
232
- ]
251
+ environmentVariables : webAppEnvWithSecret
252
+ secrets : secrets
233
253
}
234
254
}
235
255
236
- resource openAiResourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' existing =
237
- if (!empty (openAiResourceGroupName )) {
238
- name : !empty (openAiResourceGroupName ) ? openAiResourceGroupName : resourceGroup .name
256
+ resource openAIResourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' existing =
257
+ if (!empty (openAIResourceGroupName )) {
258
+ name : !empty (openAIResourceGroupName ) ? openAIResourceGroupName : resourceGroup .name
239
259
}
240
260
241
- module openAi 'core/ai/cognitiveservices.bicep' = {
261
+ module openAI 'core/ai/cognitiveservices.bicep' = if ( deployAzureOpenAI ) {
242
262
name : 'openai'
243
- scope : openAiResourceGroup
263
+ scope : openAIResourceGroup
244
264
params : {
245
265
name : '${prefix }-openai'
246
266
location : openAILocation
@@ -279,9 +299,9 @@ module openAi 'core/ai/cognitiveservices.bicep' = {
279
299
}
280
300
281
301
// USER ROLES
282
- module openAiRoleUser 'core/security/role.bicep' =
302
+ module openAIRoleUser 'core/security/role.bicep' =
283
303
if (empty (runningOnGh )) {
284
- scope : openAiResourceGroup
304
+ scope : openAIResourceGroup
285
305
name : 'openai-role-user'
286
306
params : {
287
307
principalId : principalId
@@ -291,8 +311,8 @@ module openAiRoleUser 'core/security/role.bicep' =
291
311
}
292
312
293
313
// Backend roles
294
- module openAiRoleBackend 'core/security/role.bicep' = {
295
- scope : openAiResourceGroup
314
+ module openAIRoleBackend 'core/security/role.bicep' = {
315
+ scope : openAIResourceGroup
296
316
name : 'openai-role-backend'
297
317
params : {
298
318
principalId : web .outputs .SERVICE_WEB_IDENTITY_PRINCIPAL_ID
@@ -314,13 +334,13 @@ output SERVICE_WEB_NAME string = web.outputs.SERVICE_WEB_NAME
314
334
output SERVICE_WEB_URI string = web .outputs .SERVICE_WEB_URI
315
335
output SERVICE_WEB_IMAGE_NAME string = web .outputs .SERVICE_WEB_IMAGE_NAME
316
336
317
- output AZURE_OPENAI_ENDPOINT string = deployAzureOpenAI ? openAi .outputs .endpoint : ''
318
- output AZURE_OPENAI_VERSION string = deployAzureOpenAI ? azureOpenAiAPIVersion : ''
319
- output AZURE_OPENAI_CHAT_DEPLOYMENT string = deployAzureOpenAI ? chatConfig .deploymentName : ''
320
- output AZURE_OPENAI_EMBED_DEPLOYMENT string = deployAzureOpenAI ? embedConfig .deploymentName : ''
321
- output AZURE_OPENAI_CHAT_MODEL string = deployAzureOpenAI ? chatConfig .modelName : ''
322
- output AZURE_OPENAI_EMBED_MODEL string = deployAzureOpenAI ? embedConfig .modelName : ''
323
- output AZURE_OPENAI_EMBED_MODEL_DIMENSIONS int = deployAzureOpenAI ? embedConfig .dimensions : 0
337
+ output AZURE_OPENAI_ENDPOINT string = useAzureOpenAI ? ( deployAzureOpenAI ? openAI .outputs .endpoint : azureOpenAIEndpoint ) : ''
338
+ output AZURE_OPENAI_VERSION string = useAzureOpenAI ? azureOpenAIAPIVersion : ''
339
+ output AZURE_OPENAI_CHAT_DEPLOYMENT string = useAzureOpenAI ? chatConfig .deploymentName : ''
340
+ output AZURE_OPENAI_EMBED_DEPLOYMENT string = useAzureOpenAI ? embedConfig .deploymentName : ''
341
+ output AZURE_OPENAI_CHAT_MODEL string = useAzureOpenAI ? chatConfig .modelName : ''
342
+ output AZURE_OPENAI_EMBED_MODEL string = useAzureOpenAI ? embedConfig .modelName : ''
343
+ output AZURE_OPENAI_EMBED_MODEL_DIMENSIONS int = useAzureOpenAI ? embedConfig .dimensions : 0
324
344
325
345
output POSTGRES_HOST string = postgresServer .outputs .POSTGRES_DOMAIN_NAME
326
346
output POSTGRES_USERNAME string = postgresEntraAdministratorName
0 commit comments