This sample is for educational purposes only and is not recommended for production deployments.
This sample allows you to build your own integrated large language model chat copilot. This is an enriched intelligence app, with multiple dynamic components including command messages, user intent, and memories.
The chat prompt and response will evolve as the conversation between the user and the application proceeds. This chat experience is orchestrated with Semantic Kernel and a Copilot Chat skill containing numerous functions that work together to construct each response.
Refer to ./scripts/README.md for automated configuration and local deployment of CopilotChat.
Before you get started, make sure you have the following requirements in place:
- .NET 6.0 SDK
- Node.js
- Yarn - After installation, run
yarn --version
in a terminal window to ensure you are running v1.22.19. - Azure OpenAI resource or an account with OpenAI.
- Visual Studio Code (Optional)
The sample uses two applications, a front-end web UI, and a back-end API server. First, let’s set up and verify the back-end API server is running.
-
Generate and trust a localhost developer certificate. Open a terminal and run:
- For Windows and Mac run
dotnet dev-certs https --trust
and selectYes
when asked if you want to install this certificate. - For Linux run
dotnet dev-certs https
Note: It is recommended you close all instances of your web browser after installing the developer certificates.
- For Windows and Mac run
-
Navigate to
samples/apps/copilot-chat-app/webapi
and openappsettings.json
-
Update the
AIService
configuration section:- Update
Type
to the AI service you will be using (i.e.,AzureOpenAI
orOpenAI
). - If your are using Azure OpenAI, update
Endpoint
to your Azure OpenAI resource Endpoint address (e.g.,http://contoso.openai.azure.com
).If you are using OpenAI, this property will be ignored.
- Set your Azure OpenAI or OpenAI key by opening a terminal in the webapi project directory and using
dotnet user-secrets
cd semantic-kernel/samples/apps/copilot-chat-app/webapi dotnet user-secrets set "AIService:Key" "MY_AZUREOPENAI_OR_OPENAI_KEY"
- (Optional) Update
Models
to the Azure OpenAI deployment or OpenAI models you want to use.- For
Completion
andPlanner
, CopilotChat is optimized for Chat completion models, such as gpt-3.5-turbo and gpt-4.Important: gpt-3.5-turbo is normally labelled as "
gpt-35-turbo
" (no period) in Azure OpenAI and "gpt-3.5-turbo
" (with a period) in OpenAI. - For
Embedding
,text-embedding-ada-002
is sufficient and cost-effective for generating embeddings.
- For
- Update
-
(Optional) To enable speech-to-text for chat input, update the
AzureSpeech
configuration section:If you have not already, you will need to create an Azure Speech resource (see ./webapi/appsettings.json for more details).
- Update
Region
to whichever region is appropriate for your speech sdk instance. - Set your Azure speech key by opening a terminal in the webapi project directory and setting
a dotnet user-secrets value for
AzureSpeech:Key
dotnet user-secrets set "AzureSpeech:Key" "MY_AZURE_SPEECH_KEY"
- Update
-
-
Build and run the back-end API server
-
Open a terminal and navigate to
samples/apps/copilot-chat-app/webapi
-
Run
dotnet build
to build the project. -
Run
dotnet run
to start the server. -
Verify the back-end server is responding, open a web browser and navigate to
https://localhost:40443/probe
The first time accessing the probe you may get a warning saying that there is a problem with website's certificate. Select the option to accept/continue - this is expected when running a service on
localhost
It is important to do this, as your browser may need to accept the certificate before allowing the frontend to communicate with the backend.
You may also need to acknowledge the Windows Defender Firewall, and allow the app to communicate over private or public networks as appropriate.
-
-
Build and start the front-end application
-
You will need an Azure Active Directory (AAD) application registration.
For more details on creating an application registration, go here.
- Select
Single-page application (SPA)
as platform type, and set the Web redirect URI tohttp://localhost:3000
- Select
Accounts in any organizational directory and personal Microsoft Accounts
as supported account types for this sample. - Make a note of the
Application (client) ID
from the Azure Portal, we will use of it later.
- Select
-
Open a terminal and navigate to
samples/apps/copilot-chat-app/webapp
Copy.env.example
into a new file.env
and update theREACT_APP_AAD_CLIENT_ID
with the AAD application (Client) ID created above. For example:REACT_APP_BACKEND_URI=https://localhost:40443/ REACT_APP_AAD_CLIENT_ID={Your Application (client) ID} REACT_APP_AAD_AUTHORITY=https://login.microsoftonline.com/common
For more detail on AAD authorities, see Client Application Configuration Authorities.
REACT_APP_SK_API_KEY
is only required if you're using an Semantic Kernel service deployed to Azure. See the Authorization section of Deploying Semantic Kernel to Azure in a web app service for more details and instruction on how to find your API key.REACT_APP_SK_API_KEY={Your API Key, should be the same as Authorization:ApiKey from appsettings.json}
-
To build and run the front-end application
yarn install yarn start
To run the WebApp with HTTPs, see How to use HTTPS for local development.
-
With the back end and front end running, your web browser should automatically launch and navigate to
http://localhost:3000
The first time running the front-end application may take a minute or so to start.
-
Sign in with a Microsoft personal account or a "Work or School" account.
-
Consent permission for the application to read your profile information (i.e., your name).
If you you experience any errors or issues, consult the troubleshooting section below.
-
-
Have fun!
Note: Each chat interaction will call Azure OpenAI/OpenAI which will use tokens that you may be billed for.
The WebApp can display this error when the application is configured for an active directory tenant, (e.g., personal/MSA accounts) and the browser attempts to use single sign-on with an account from another tenant (e.g., work or school account). Either user a private/incognito browser tab or clear your browser credentials/cookies.
CopilotChat supports chat completion models, such as gpt-3.5-*
and gpt-4-*
.
See OpenAI's model compatibility for
the complete list of current models supporting chat completions.
If you are stopped at an error message similar to the one above, your browser may be blocking the front-end access to the back end while waiting for your permission to connect. To resolve this, try the following:
- Confirm the backend service is running by opening a web browser, and navigating to
https://localhost:40443/probe
- You should see a confirmation message:
Semantic Kernel service is up and running
- You should see a confirmation message:
- If your browser asks you to acknowledge the risks of visiting an insecure website, you must acknowledge the
message before the front end will be allowed to connect to the back-end server.
- Acknowledge, continue, and navigate until you see the message Semantic Kernel service is up and running
- Navigate to
http://localhost:3000
or refresh the page to use the Copilot Chat application.
The webapp uses packages that are only supported by classic Yarn (v1.x). If you have Yarn v2.x+, run the following commands in your preferred shell to flip Yarn to the classic version.
npm install -g yarn
yarn set version classic
You can confirm the active Yarn version by running yarn --version
.
- Import Document Application: Import a document to the memory store.