Skip to content

Commit

Permalink
fixed spelling on cosmos
Browse files Browse the repository at this point in the history
  • Loading branch information
thivy committed Aug 5, 2023
1 parent 0df20dd commit 4890226
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ Below are the required environment variables, to be added to the Azure Portal or
| AUTH_GITHUB_SECRET | | Client Secret of your GitHub OAuth application |
| NEXTAUTH_SECRET | | Used to encrypt the NextAuth.js JWT, and to hash email verification tokens. **This set by default as part of the deployment template** |
| NEXTAUTH_URL | | Current webs hosting domain name with HTTP or HTTPS. **This set by default as part of the deployment template** |
| AZURE_COSMOSEDB_URI | | URL of the Azure CosmosDB |
| AZURE_COSMOSEDB_KEY | | API Key for Azure Cosmos DB |
| AZURE_COSMOSDB_URI | | URL of the Azure CosmosDB |
| AZURE_COSMOSDB_KEY | | API Key for Azure Cosmos DB |
| AZURE_AD_CLIENT_ID | | The client id specific to the application |
| AZURE_AD_CLIENT_SECRET | | The client secret specific to the application |
| AZURE_AD_TENANT_ID | | The organisation Tenant ID |
Expand Down
8 changes: 4 additions & 4 deletions src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ NEXTAUTH_SECRET=AZURE-OPENIAI-CHATGPT-NEXTAUTH-OWNKEY@1
NEXTAUTH_URL=http://localhost:3000

# Update your Cosmos Environment details here
AZURE_COSMOSEDB_URI=https://<cosmoresourcename>.documents.azure.com:443/
AZURE_COSMOSEDB_KEY=
AZURE_COSMOSDB_URI=https://<cosmoresourcename>.documents.azure.com:443/
AZURE_COSMOSDB_KEY=

# Update your Cosmos DB_NAME and CONTAINER_NAME if you want to overwrite the default values
AZURE_COSMOSEDBDB_DB_NAME=chat
AZURE_COSMOSEDBDB_CONTAINER_NAME=history
AZURE_COSMOSDB_DB_NAME=chat
AZURE_COSMOSDB_CONTAINER_NAME=history
19 changes: 11 additions & 8 deletions src/features/common/cosmos.ts
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;
};

0 comments on commit 4890226

Please sign in to comment.