forked from Azure-Samples/cosmosdb-chatgpt
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathazuredeploy.bicep
217 lines (198 loc) · 5.48 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
@description('Location where all resources will be deployed. This value defaults to the **South Central US** region.')
@allowed([
'South Central US'
'East US'
])
param location string = 'South Central US'
@description('''
Unique name for the chat application. The name is required to be unique as it will be used as a prefix for the names of these resources:
- Azure Cosmos DB
- Azure App Service
- Azure OpenAI
The name defaults to a unique string generated from the resource group identifier.
''')
param name string = uniqueString(resourceGroup().id)
@description('Boolean indicating whether Azure Cosmos DB free tier should be used for the account. This defaults to **true**.')
param cosmosDbEnableFreeTier bool = true
@description('Specifies the SKU for the Azure App Service plan. Defaults to **F1**')
@allowed([
'F1'
'D1'
'B1'
])
param appServiceSku string = 'F1'
@description('Specifies the SKU for the Azure OpenAI resource. Defaults to **S0**')
@allowed([
'S0'
])
param openAiSku string = 'S0'
@description('Git repository URL for the chat application. This defaults to the [`azure-samples/cosmosdb-chatgpt`](https://github.com/azure-samples/cosmosdb-chatgpt) repository.')
param appGitRepository string = 'https://github.com/azure-samples/cosmosdb-chatgpt.git'
@description('Git repository branch for the chat application. This defaults to the [**main** branch of the `azure-samples/cosmosdb-chatgpt`](https://github.com/azure-samples/cosmosdb-chatgpt/tree/main) repository.')
param appGetRepositoryBranch string = 'main'
var openAiSettings = {
name: '${name}-openai'
sku: openAiSku
maxTokens: '3000'
model: {
name: 'text-davinci-003'
version: '1'
deployment: {
name: 'chatmodel'
}
}
}
var cosmosDbSettings = {
name: '${name}-cosmos-nosql'
enableFreeTier: cosmosDbEnableFreeTier
database: {
name: 'chatdatabase'
}
container: {
name: 'chatcontainer'
throughput: 400
}
}
var appServiceSettings = {
plan: {
name: '${name}-web-plan'
}
web: {
name: '${name}-web'
git: {
repo: appGitRepository
branch: appGetRepositoryBranch
}
}
sku: appServiceSku
}
resource cosmosDbAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = {
name: cosmosDbSettings.name
location: location
kind: 'GlobalDocumentDB'
properties: {
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
}
databaseAccountOfferType: 'Standard'
enableFreeTier: cosmosDbSettings.enableFreeTier
locations: [
{
failoverPriority: 0
isZoneRedundant: false
locationName: location
}
]
}
}
resource cosmosDbDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-08-15' = {
parent: cosmosDbAccount
name: cosmosDbSettings.database.name
properties: {
resource: {
id: cosmosDbSettings.database.name
}
}
}
resource cosmosDbContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-08-15' = {
parent: cosmosDbDatabase
name: cosmosDbSettings.container.name
properties: {
resource: {
id: cosmosDbSettings.container.name
partitionKey: {
paths: [
'/sessionId'
]
kind: 'Hash'
version: 2
}
indexingPolicy: {
indexingMode: 'Consistent'
automatic: true
includedPaths: [
{
path: '/sessionId/?'
}
{
path: '/type/?'
}
]
excludedPaths: [
{
path: '/*'
}
]
}
}
options: {
throughput: cosmosDbSettings.container.throughput
}
}
}
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 openAiModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2022-12-01' = {
parent: openAiAccount
name: openAiSettings.model.deployment.name
properties: {
model: {
format: 'OpenAI'
name: openAiSettings.model.name
version: openAiSettings.model.version
}
scaleSettings: {
scaleType: 'Standard'
}
}
}
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
name: appServiceSettings.plan.name
location: location
sku: {
name: appServiceSettings.sku
}
}
resource appServiceWeb 'Microsoft.Web/sites@2022-03-01' = {
name: appServiceSettings.web.name
location: location
properties: {
serverFarmId: appServicePlan.id
httpsOnly: true
}
}
resource appServiceWebSettings 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appServiceWeb
name: 'appsettings'
kind: 'string'
properties: {
COSMOSDB__ENDPOINT: cosmosDbAccount.properties.documentEndpoint
COSMOSDB__KEY: cosmosDbAccount.listKeys().primaryMasterKey
COSMOSDB__DATABASE: cosmosDbDatabase.name
COSMOSDB__CONTAINER: cosmosDbContainer.name
OPENAI__ENDPOINT: openAiAccount.properties.endpoint
OPENAI__KEY: openAiAccount.listKeys().key1
OPENAI__DEPLOYMENT: openAiModelDeployment.name
OPENAI__MAXTOKENS: openAiSettings.maxTokens
}
}
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
}
}
output deployedUrl string = appServiceWeb.properties.defaultHostName