Skip to content

Commit

Permalink
Add CosmosDB to deployment templates (microsoft#892)
Browse files Browse the repository at this point in the history
### Motivation and Context
We want to be able to store messages and chat sessions across reboots of
the SK server.

### Description
Added deployment of Cosmos DB, an account and two containers for storing
chats and their messages.
  • Loading branch information
glahaye committed May 10, 2023
1 parent b9ddc82 commit 878587a
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Licensed under the MIT license. See LICENSE file in the project root for full li
Bicep template for deploying Semantic Kernel to Azure as a web app service without creating a new Azure OpenAI instance.
Resources to add:
- CosmosDB
- vNet + Network security group
*/

Expand Down Expand Up @@ -134,7 +133,23 @@ resource appServiceWeb 'Microsoft.Web/sites@2022-03-01' = {
}
{
name: 'ChatStore:Type'
value: 'volatile'
value: 'cosmos'
}
{
name: 'ChatStore:Cosmos:Database'
value: 'CopilotChat'
}
{
name: 'ChatStore:Cosmos:ChatSessionsContainer'
value: 'chatsessions'
}
{
name: 'ChatStore:Cosmos:ChatMessagesContainer'
value: 'chatmessages'
}
{
name: 'ChatStore:Cosmos:ConnectionString'
value: cosmosAccount.listConnectionStrings().connectionStrings[0].connectionString
}
{
name: 'MemoriesStore:Type'
Expand Down Expand Up @@ -311,6 +326,94 @@ resource aci 'Microsoft.ContainerInstance/containerGroups@2022-10-01-preview' =
}
}

resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
name: toLower('cosmos-${uniqueName}')
location: location
kind: 'GlobalDocumentDB'
properties: {
consistencyPolicy: { defaultConsistencyLevel: 'Session' }
locations: [ {
locationName: location
failoverPriority: 0
isZoneRedundant: false
}
]
databaseAccountOfferType: 'Standard'
}
}

resource cosmosDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-05-15' = {
parent: cosmosAccount
name: 'CopilotChat'
properties: {
resource: {
id: 'CopilotChat'
}
}
}

resource messageContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-03-15' = {
parent: cosmosDatabase
name: 'chatmessages'
properties: {
resource: {
id: 'chatmessages'
indexingPolicy: {
indexingMode: 'consistent'
automatic: true
includedPaths: [
{
path: '/*'
}
]
excludedPaths: [
{
path: '/"_etag"/?'
}
]
}
partitionKey: {
paths: [
'/id'
]
kind: 'Hash'
version: 2
}
}
}
}

resource sessionContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-03-15' = {
parent: cosmosDatabase
name: 'chatsessions'
properties: {
resource: {
id: 'chatsessions'
indexingPolicy: {
indexingMode: 'consistent'
automatic: true
includedPaths: [
{
path: '/*'
}
]
excludedPaths: [
{
path: '/"_etag"/?'
}
]
}
partitionKey: {
paths: [
'/id'
]
kind: 'Hash'
version: 2
}
}
}
}

resource speechAccount 'Microsoft.CognitiveServices/accounts@2022-12-01' = {
name: 'cog-${uniqueName}'
location: location
Expand Down
107 changes: 105 additions & 2 deletions samples/apps/copilot-chat-app/webapi/DeploymentTemplates/sk.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Licensed under the MIT license. See LICENSE file in the project root for full li
Bicep template for deploying Semantic Kernel to Azure as a web app service.
Resources to add:
- CosmosDB
- vNet + Network security group
*/

Expand Down Expand Up @@ -144,7 +143,23 @@ resource appServiceWeb 'Microsoft.Web/sites@2022-03-01' = {
}
{
name: 'ChatStore:Type'
value: 'volatile'
value: 'cosmos'
}
{
name: 'ChatStore:Cosmos:Database'
value: 'CopilotChat'
}
{
name: 'ChatStore:Cosmos:ChatSessionsContainer'
value: 'chatsessions'
}
{
name: 'ChatStore:Cosmos:ChatMessagesContainer'
value: 'chatmessages'
}
{
name: 'ChatStore:Cosmos:ConnectionString'
value: cosmosAccount.listConnectionStrings().connectionStrings[0].connectionString
}
{
name: 'MemoriesStore:Type'
Expand Down Expand Up @@ -321,6 +336,94 @@ resource aci 'Microsoft.ContainerInstance/containerGroups@2022-10-01-preview' =
}
}

resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
name: toLower('cosmos-${uniqueName}')
location: location
kind: 'GlobalDocumentDB'
properties: {
consistencyPolicy: { defaultConsistencyLevel: 'Session' }
locations: [ {
locationName: location
failoverPriority: 0
isZoneRedundant: false
}
]
databaseAccountOfferType: 'Standard'
}
}

resource cosmosDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-05-15' = {
parent: cosmosAccount
name: 'CopilotChat'
properties: {
resource: {
id: 'CopilotChat'
}
}
}

resource messageContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-03-15' = {
parent: cosmosDatabase
name: 'chatmessages'
properties: {
resource: {
id: 'chatmessages'
indexingPolicy: {
indexingMode: 'consistent'
automatic: true
includedPaths: [
{
path: '/*'
}
]
excludedPaths: [
{
path: '/"_etag"/?'
}
]
}
partitionKey: {
paths: [
'/id'
]
kind: 'Hash'
version: 2
}
}
}
}

resource sessionContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-03-15' = {
parent: cosmosDatabase
name: 'chatsessions'
properties: {
resource: {
id: 'chatsessions'
indexingPolicy: {
indexingMode: 'consistent'
automatic: true
includedPaths: [
{
path: '/*'
}
]
excludedPaths: [
{
path: '/"_etag"/?'
}
]
}
partitionKey: {
paths: [
'/id'
]
kind: 'Hash'
version: 2
}
}
}
}

resource speechAccount 'Microsoft.CognitiveServices/accounts@2022-12-01' = {
name: 'cog-${uniqueName}'
location: location
Expand Down

0 comments on commit 878587a

Please sign in to comment.