Copilot
Software Copilot are a new kind of assistant embedded in your app/product. They are designed to help users get the most out of your app by providing contextual guidance and take actions on their behalf.
Preview
Contact us to get advice on how to ship reliable and secure AI Copilots or Assistants in your product.
Supported Features
Message | Streaming | Elements | Audio | Ask User | Chat History | Chat Profiles | Feedback |
---|---|---|---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
Embedding the Copilot
First, make sure your Chainlit server is running. Then, add the following script at the end of your website’s <body>
tag:
This example assumes your Chainlit server is running on
http://localhost:8000
Remember the HTML file has to be served by a server, opening it directly in your browser won’t work. You can use simple HTTP server for tests purpose.
That’s it! You should now see a floating button on the bottom right corner of your website. Clicking on it will open the Copilot.
Widget Configuration
The mountChainlitWidget
function accepts the following options:
Function Calling
The Copilot can call functions on your website. This is useful for taking actions on behalf of the user. For example, you can call a function to create a new document, or to open a modal.
First, create a CopilotFunction
in your Chainlit server:
Then, in your app/website, add the following event listener:
As you can see, the event listener receives the function name, arguments, and a callback function. The callback function should be called with the result of the function call.
Send a Message
The Copilot can also send messages directly to the Chainlit server. This is useful for sending context information or user actions to the Chainlit server (like the user selected from cell A1 to B1 on a table).
First, update the @cl.on_message
decorated function to your Chainlit server:
Then, in your app/website, you can emit an event like this:
Security
Cross Origin Resource Sharing (CORS)
By default, the Chainlit server accepts requests from any origin. This is useful for development, but not recommended for production.
To restrict the origins that can access the server (hence embed the copilot), set the allow_origins config field to a list of allowed origins.
Authentication
If you want to restrict access to the Copilot per user, you can enable authentication on the Chainlit server.
While the standalone Chainlit application handles the authentication process, the Copilot needs to be configured with an access token. This token is used to authenticate the user with the Chainlit server.
The host app/website is responsible for generating the token and passing it to the Copilot. Here are examples of how to generate the token in different languages:
You will need the CHAINLIT_AUTH_SECRET
you generated when configuring
authentication.
Was this page helpful?