Sample application that combines Azure Cosmos DB with Azure OpenAI ChatGPT service
This sample application combines Azure Cosmos DB with Azure OpenAI ChatGPT with a Blazor front-end for an intelligent chat bot application that is a minimal clone of the OpenAi ChatGPT experience.
This application has individual chat sessions which are displayed and can be selected in the left-hand nav. Clicking on a session will show the messages that contain human prompts and AI completions.
When a new prompt is sent to the Azure OpenAI service, some of the conversation history is sent with it. This provides context allowing ChatGPT to respond
as though it is having a conversation. The length of this conversation history can be configured from appsettings.json
with the OpenAiMaxTokens
value that is then translated to a maximum conversation string length that is 1/2 of this value.
Please note that the "text-davinci-003" model used by this sample has a maximum of 4096 tokens. Token are used in both the request and reponse from the service. Overriding the maxConversationLength to values approaching maximum token value could result in completions that contain little to no text if all of it has been used in the request.
The history for all prompts and completions for each chat session is stored in Azure Cosmos DB. Deleting a chat session in the UI will delete it's corresponding data as well.
The application will also summarize the name of the chat session by asking ChatGPT to provide a one or two word summary of the first prompt. This allows you to easily identity different chat sessions.
Please note this is a sample application. It is intended to demonstrate how to use Azure Cosmos DB and Azure OpenAI ChatGPT together. It is not intended for production or other large scale use
The provided ARM or Bicep Template will provision the following resources:
Note: You must have access to Azure Open AI service from your subscription before attempting to deploy this application.
All connection information for Azure Cosmos DB and Open AI is zero-touch and injected as environment variables in the Azure App Service instance at deployment time.
To remove all the resources used by this sample, you must first manually delete the deployed model within the Azure AI service. You can then delete the resource group for your deployment. This will delete all remaining resources.