-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOutputCacheDallESample.bicep
More file actions
221 lines (205 loc) · 5.63 KB
/
OutputCacheDallESample.bicep
File metadata and controls
221 lines (205 loc) · 5.63 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
param name string
param location string = resourceGroup().location
param tags object = {}
param identityName string
param containerRegistryName string
param containerAppsEnvironmentName string
param applicationInsightsName string
param exists bool
param openAiSku object = {
name:'S0'
}
var embeddingDeploymentCapacity = 30
var redisPort = 10000
var openai_deployments = [
{
name: 'text-embedding-ada-002'
model_name: '${name}-textembedding'
version: '2'
raiPolicyName: 'Microsoft.Default'
sku_capacity: embeddingDeploymentCapacity
sku_name: 'Standard'
}
{
name: 'dall-e-3'
model_name: 'dall-e-3'
version: '3.0'
raiPolicyName: 'Microsoft.Default'
sku_capacity: 1
sku_name: 'Standard'
}
]
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: identityName
location: location
}
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = {
name: containerRegistryName
}
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-04-01-preview' existing = {
name: containerAppsEnvironmentName
}
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
name: applicationInsightsName
}
resource acrPullRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: containerRegistry
name: guid(subscription().id, resourceGroup().id, identity.id, 'acrPullRole')
properties: {
roleDefinitionId: subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')
principalType: 'ServicePrincipal'
principalId: identity.properties.principalId
}
}
module fetchLatestImage '../modules/fetch-container-image.bicep' = {
name: '${name}-fetch-image'
params: {
exists: exists
name: name
}
}
resource app 'Microsoft.App/containerApps@2023-04-01-preview' = {
name: name
location: location
tags: union(tags, {'azd-service-name': 'OutputCacheDallESample' })
dependsOn: [ acrPullRole]
identity: {
type: 'UserAssigned'
userAssignedIdentities: { '${identity.id}': {} }
}
properties: {
managedEnvironmentId: containerAppsEnvironment.id
configuration: {
ingress: {
external: true
targetPort: 8080
transport: 'auto'
}
registries: [
{
server: '${containerRegistryName}.azurecr.io'
identity: identity.id
}
]
secrets: [
]
}
template: {
containers: [
{
image: fetchLatestImage.outputs.?containers[?0].?image ?? 'cathyxwang/outputcachedallesample:latest'
name: 'main'
env: [
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: applicationInsights.properties.ConnectionString
}
{
name: 'PORT'
value: '8080'
}
{
name: 'apiKey'
value: cognitiveAccount.listKeys().key1
}
{
name: 'AZURE_OPENAI_ENDPOINT'
value: cognitiveAccount.properties.endpoint
}
{
name: 'AOAIResourceName'
value: cognitiveAccount.name
}
{
name: 'AOAIEmbeddingDeploymentName'
value: '${name}-textembedding'
}
{
name: 'apiUrl'
value: '${cognitiveAccount.properties.endpoint}openai/deployments/Dalle3/images/generations?api-version=2024-02-01'
}
{
name: 'RedisCacheConnection'
value: '${redisCache.properties.hostName}:10000,password=${redisdatabase.listKeys().primaryKey},ssl=True,abortConnect=False'
}
{
name:'SemanticCacheAzureProvider'
value: 'rediss://:${redisdatabase.listKeys().primaryKey}@${redisCache.properties.hostName}:10000'
}
]
resources: {
cpu: json('1.0')
memory: '2.0Gi'
}
}
]
scale: {
minReplicas: 1
maxReplicas: 10
}
}
}
}
//azure open ai resource
resource cognitiveAccount 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
name: '${name}-csaccount'
location: location
tags: tags
kind: 'OpenAI'
properties: {
customSubDomainName: '${name}-csaccount'
publicNetworkAccess: 'Enabled'
apiProperties: {
enableDallE: true
}
}
sku: openAiSku
}
@batchSize(1)
resource model 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = [for deployment in openai_deployments: {
name: deployment.model_name
parent: cognitiveAccount
sku: {
name: deployment.sku_name
capacity: deployment.sku_capacity
}
properties: {
model: {
format: 'OpenAI'
name: deployment.name
version: deployment.version
}
raiPolicyName: deployment.raiPolicyName
}
}]
//azure cache for redis resource
resource redisCache 'Microsoft.Cache/redisEnterprise@2024-02-01' = {
location:location
name: '${name}-rediscache'
sku:{
capacity:2
name: 'Enterprise_E10'
}
}
resource redisdatabase 'Microsoft.Cache/redisEnterprise/databases@2024-02-01' = {
name: 'default'
parent: redisCache
properties:{
evictionPolicy:'NoEviction'
clusteringPolicy:'EnterpriseCluster'
modules:[
{
name: 'RediSearch'
}
{
name:'RedisJSON'
}
]
port: redisPort
}
}
output defaultDomain string = containerAppsEnvironment.properties.defaultDomain
output name string = app.name
output uri string = 'https://${app.properties.configuration.ingress.fqdn}'
output id string = app.id