forked from matijagrcic/azurechatgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
17 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
"use server"; | ||
import { CosmosClient } from "@azure/cosmos"; | ||
|
||
// Read Cosmos DB_NAME and CONTAINER_NAME from .env | ||
const DB_NAME = process.env.AZURE_COSMOSEDBDB_DB_NAME || "chat"; | ||
const CONTAINER_NAME = process.env.AZURE_COSMOSEDBDB_CONTAINER_NAME || "history"; | ||
// Read Cosmos DB_NAME and CONTAINER_NAME from .env | ||
const DB_NAME = process.env.AZURE_COSMOSDB_DB_NAME || "chat"; | ||
const CONTAINER_NAME = process.env.AZURE_COSMOSDB_CONTAINER_NAME || "history"; | ||
|
||
export const memoryContainer = async () => { | ||
const endpoint = process.env.AZURE_COSMOSDB_URI!; | ||
const key = process.env.AZURE_COSMOSDB_KEY!; | ||
const client = new CosmosClient({ endpoint, key }); | ||
|
||
await client.databases.createIfNotExists({ id: DB_NAME }); | ||
const databaseResponse = await client.databases.createIfNotExists({ | ||
id: DB_NAME, | ||
}); | ||
|
||
const containerRepose = await client | ||
.database(DB_NAME) | ||
.containers.createIfNotExists({ id: CONTAINER_NAME }); | ||
const containerResponse = | ||
await databaseResponse.database.containers.createIfNotExists({ | ||
id: CONTAINER_NAME, | ||
}); | ||
|
||
return containerRepose.container; | ||
return containerResponse.container; | ||
}; |