forked from Azure-Samples/cosmosdb-chatgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azuredeploy.bicep
200 lines (183 loc) · 4.6 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
param location string = resourceGroup().location
@description('Name of the chat application. Needs to be unique for Cosmos DB, App Service and Open AI')
param chatAppName string
@description('OpenAI region')
@allowed([
'East US'
'South Central US'
'West Europe'
])
param openAiRegion string = 'East US'
@description('OpenAI SKU')
@allowed([
'S0'
])
param openAiSku string = 'S0'
@description('The deployment name for the Davinci-003 model used by this application')
param openAIModelDeploymentName string = ''
@description('Specifies App Service Sku (F1 = Free Tier)')
param appServicesSkuName string = 'F1'
@description('Specifies App Service capacity')
param appServicesSkuCapacity int = 1
@description('Enable Cosmos DB Free Tier')
param cosmosFreeTier bool = true
@description('Cosmos DB Container Throughput (<1000 for free tier)')
param cosmosContainerThroughput int = 400
var cosmosDBAccountName = '${chatAppName}-cosmos'
var openAiAccountName = '${chatAppName}-openai'
var hostingPlanName = '${chatAppName}-hostingplan'
var webSiteName = '${chatAppName}-webapp'
var webSiteRepository = 'https://github.com/Azure-Samples/cosmos-chatgpt.git'
var databaseName = 'ChatDatabase'
var containerName = 'ChatContainer'
var openAiMaxTokens = '3000'
resource cosmosDBAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = {
name: cosmosDBAccountName
location: location
kind: 'GlobalDocumentDB'
properties: {
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
}
databaseAccountOfferType: 'Standard'
enableFreeTier: cosmosFreeTier
locations: [
{
failoverPriority: 0
isZoneRedundant: false
locationName: location
}
]
}
}
resource cosmosDBAccountName_database 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-08-15' = {
parent: cosmosDBAccount
name: databaseName
properties: {
resource: {
id: databaseName
}
}
}
resource cosmosDBAccountName_databaseName_container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-08-15' = {
parent: cosmosDBAccountName_database
name: containerName
properties: {
resource: {
id: containerName
partitionKey: {
paths: [
'/ChatSessionId'
]
kind: 'Hash'
version: 2
}
indexingPolicy: {
indexingMode: 'Consistent'
automatic: true
includedPaths: [
{
path: '/ChatSessionId/?'
}
{
path: '/Type/?'
}
]
excludedPaths: [
{
path: '/*'
}
]
}
}
options: {
throughput: cosmosContainerThroughput
}
}
}
resource openAiAccount 'Microsoft.CognitiveServices/accounts@2022-12-01' = {
name: openAiAccountName
location: openAiRegion
sku: {
name: openAiSku
}
kind: 'OpenAI'
properties: {
customSubDomainName: openAiAccountName
publicNetworkAccess: 'Enabled'
}
}
resource openAiAccountName_openAIModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2022-12-01' = {
parent: openAiAccount
name: openAIModelDeploymentName
properties: {
model: {
format: 'OpenAI'
name: 'text-davinci-003'
version: '1'
}
scaleSettings: {
scaleType: 'Standard'
}
}
}
resource hostingPlan 'Microsoft.Web/serverfarms@2020-12-01' = {
name: hostingPlanName
location: location
sku: {
name: appServicesSkuName
capacity: appServicesSkuCapacity
}
}
resource webSite 'Microsoft.Web/sites@2020-12-01' = {
name: webSiteName
location: location
properties: {
serverFarmId: hostingPlan.id
siteConfig: {
appSettings: [
{
name: 'CosmosUri'
value: cosmosDBAccount.properties.documentEndpoint
}
{
name: 'CosmosKey'
value: cosmosDBAccount.listKeys().primaryMasterKey
}
{
name: 'CosmosDatabase'
value: databaseName
}
{
name: 'CosmosContainer'
value: containerName
}
{
name: 'OpenAiUri'
value: openAiAccount.properties.endpoint
}
{
name: 'OpenAiKey'
value: openAiAccount.listKeys().key1
}
{
name: 'OpenAiDeployment'
value: openAIModelDeploymentName
}
{
name: 'OpenAiMaxTokens'
value: openAiMaxTokens
}
]
}
}
}
resource webSiteName_web 'Microsoft.Web/sites/sourcecontrols@2020-12-01' = {
parent: webSite
name: 'web'
properties: {
repoUrl: webSiteRepository
branch: 'main'
isManualIntegration: true
}
}