- If the user clicks on the “Products” button, we want to show a list of products the company offers.
- If the user clicks on the “Locations” button, we want to show a list of locations the company has.
Conceptual Overview
At a high level, the interaction between the user and the backend is as follows:- User clicks on the “Products” button.
- The system invokes the
onAction
callback with 2 arguments:llmFriendlyMessage
andhumanFriendlyMessage
.- The
llmFriendlyMessage
is the text that will be sent to the backend to fetch the products. - The
humanFriendlyMessage
is the text that will can be shown to the user if needed.
- The
- UI makes a call to the backend with the
llmFriendlyMessage
andpreviousMessages
that contains the current state of the UI.
The current state of the UI is helpful for the LLM to understand the context of the user’s request. For example, lets say the user has already searched forapple.com
and clicked on theProducts
button. Given this context, the LLM can use this information to fetchProducts for apple.com
. - The backend will generate a response and send it back to the frontend.
- The frontend will update the UI with the new response which contains the products or locations based on what the user clicked on.
- The new generation might again contain more buttons or forms and this process continues.
Implementation
This guide will show you how to build this interactive component.1
Add buttons to the Generated UI
src/api/route.tsx
2
Add a button handler
Pass in the
onAction
callback to the C1Component
. This callback will be called when the user clicks on the button.
The argument to the callback is an object with two properties: llmFriendlyMessage
and humanFriendlyMessage
wherellmFriendlyMessage
is the text that will be sent to the backend to fetch the productshumanFriendlyMessage
is the text that will can be shown to the user (if needed, for example in chatbots)
src/app/page.tsx
3
Call the backend endpoint and update the UI with the response
src/app/page.tsx