Moving to ai/rsc
Concepts
To go beyond text, we'll be using a concept we explored in an earlier section, tools. Remember, tools are like programs we can give to the model, and the model can decide as and when to use based on the context of the conversation.
With ai/rsc
's streamUI
function, you can provide tools that return React components, rather than arbitrary values.
With streamUI
, the model becomes a dynamic router that is able to understand the users' intention and display the relevant UI as required.
Implementation
In this section, you will update your chatbot to use the ai/rsc
library.
Create a Server Action at app/actions.tsx
and add the following code:
Open your root layout (app/layout.tsx
) and wrap the children with the AI
provider created in the previous step.
Replace your root page (app/page.tsx
) with the following code.
Make sure your dev server is running.
Head to localhost:3000 and send a message to your chatbot!