Responding with UI
Learn how to respond to user input with a UI.
The copilot offer the ability to respond with highly customizable UIs. This way you can create a more interactive experience for your users.
These UIs can be used for a variety of purposes, such as:
- Displaying information in a more user-friendly way
- Collecting user input
- Providing a more interactive experience for the user (from simple buttons to complex forms)
- Showing progress or status updates, videos, images, and more
- Toggle dark mode, change language, and other settings.
Example
We will create a simple copilot that have access to real time weather data and display it in a UI.
- After creating the copilot, create a new action called
getTheWeather
, make sure the action type isGET
, and pass the following URL:
You should have seomthing like this image:
-
Now, embed the copilot using our React component :
-
Create a new file called
WeatherRenderer.js
and add the following code:
This file contain the UI that will be displayed to the user. It’s a simple card that display the current weather and a graph that show the hourly forecast, you have a lot of flexibility to create the UI that you want, just make sure the GetWetherDataRenderer
function return a valid JSX.
Also, notice that the UI will consume the data that the copilot action will return, so make sure to define the type of the data that the action will return in the Props
type.
-
Make sure that component you created is being defined in the copilot options:
-
Now, when we try to chat with the copilot and ask for the weather, we will get a UI that display the current weather and the hourly forecast.