React Server Components in AI Applications

Rate this content
Bookmark

In this talk, we will explore how we can use AI to enhance user experience by having large language models return interactive React Components that we define to our users. This way, instead of instructing users on what to do with text, our applications can present interactive user interface elements directly in response to a user query. We discuss this briefly in this PodRocket episode where the Vercel CTO says it could be game changing. In this talk, we teach developers how to implement such functionality in their applications.

This talk has been presented at React Advanced 2024, check out the latest edition of this React Conference.

FAQ

He aims to solve the issue of ineffective natural language search on platforms like Netflix by using AI and vector embeddings to provide more accurate search results.

The Vercel AI SDK is used to enable AI in the movie app, allowing for more interactive and accurate search capabilities.

Vector search works by comparing the vector of a user's query to the vector of an item, like a movie name, to find the closest match in the database.

Generative UI refers to creating dynamic and interactive user interfaces by using AI tools to query databases and render components like movie details.

Movies++ is a movie app being developed to improve movie search using AI-enabled React server components and a vector database.

He handles AI non-determinism by pre-defining components to ensure consistent rendering, allowing more control over how the UI looks.

His presentation covers vector embeddings, natural language search, and generative UI using React server components and AI.

Tejas Kumar discusses the use of React server components with AI, focusing on how vector embeddings can improve search experiences.

Vector embeddings are generated by specialized machine-learning models that convert natural language into a list of numbers, allowing for comparison in space to improve search accuracy.

Tejas Kumar is a developer relations engineer for generative AI at DataStax, with over 20 years of experience building on the web at companies like Ressel, Spotify, and Zeta.

Tejas Kumar
Tejas Kumar
17 min
28 Oct, 2024

Comments

Sign in or register to post your comment.
  • Va Da
    Va Da
    P4
    Interesting way to combine React hooks with UI state.
Video Summary and Transcription
Today we will discuss React server components with AI and how to build a better search experience using them. We will learn how to make a Next.js app AI-enabled using the Vercel AI SDK. The Vercel AI SDK's streamUI function with the GPT 4.0 model will be used to make suggestions interactive. We will explore the use of history and conversation in AI and how to continue the conversation and read the result. The concept of generative UI with the vector database will be introduced, along with querying the database for movies. We will process user queries and return movies based on them. The power of React server components in enhancing UI will be demonstrated. In summary, the Talk covers vector embeddings, natural language search, and generative UI.

1. Introduction to React Server Components with AI

Short description:

Today, I want to talk to you specifically about React server components with AI. We're going to build a better search experience using React Server Components by querying a vector database called Astra. This is a huge part of generative AI.

♪ Hey, I'm Tejas Kumar, and I've been building on the web for over 20 years at places like Ressel, Spotify, Zeta, and more. Today, I'm a developer relations engineer for generative AI at DataStax, but I'm not here to talk about any of that. Today, I want to talk to you specifically about React server components with AI.

And look, I don't want to take too much time, so let's just get straight into the demo. Here's what we have. So I love Netflix. I use Netflix a lot, but oftentimes, when I search for things, I search in natural language, like movies with a strong female lead, something like this, you know? And usually, it doesn't match. And that's a real problem with the Internet today, is like, we think in natural language, but if I want to watch just a movie with superheroes, I can't type this without getting just a non-answer.

This is changing with AI and React server components, and the way it's changing is through vector embeddings. Now, we need to spend a little bit of time talking about them because they're really powerful. Vector embeddings are generated by very specialized machine-learning models that take in natural language and output a big list of numbers. How they can do this is because these numbers are comparable in space. What does that mean? If we think about a vector, a three-dimensional vector, that's just space, right? There's horizontal, vertical, and depth. That's 3D space, three-dimensional space, which is represented by a three-dimensional vector. Now, if I say words like dog and cat and pet are all over here, and words like airplane and aluminum are sort of over here, and words like React and Angular and Solid are all over here, you see, it's moving around space, and we're putting things in different places.

That's what an embeddings model does. It literally just embeds vector representations of natural language in space. When you have those, you can then compare the space given by the vector of a user's query to the space of a thing, like a movie name, and find things that are closer. Literally, this is how vector search works. And this is a huge part of generative AI. So together, what we're going to do is build a better search experience using React Server Components. The way we're going to do that is by querying this database. You need to have your vectors live somewhere. At Datastacks, we make a vector database called Astra, and we loaded a bunch of movies here into this database. And you can see their vector representations if you look at this field here. So I'm just going to copy that, and I'm going to paste it. This is the vector representation for one of the movies. It's kind of nuts. It's just like this huge array of just coordinates, right? And so we're going to query this and build some things. What we're going to build is a movie app called Movies++.

2. Making a Next.js App AI-Enabled with Vercel AI SDK

Short description:

We're going to code together to make a Next.js app AI-enabled using the Vercel AI SDK.

It looks like this. And what I want is to search for movies with superheroes, and have it do stuff. But it doesn't exist now. We're going to code this together in real time.

So to do that, let's just open our editor. And this is a Next.js app. You can see that by the app directory. And every Next.js app starts with pretty much a layout. So this is our layout. It's just HTML body children. Inside the layout, we've got a page. That's our homepage. If we go split-screen, what we can see is we have the header, the logo, and the search form. And in the search form, we have a text input and some suggestions. And this is all live, meaning if I change this whole suggestion to like, hi, it'll just update. You see? It says hi. And so this is all live. And what we're going to do is make this AI-enabled, okay?

We're going to do that using the Vercel AI SDK. So how do we do that? Well, let's make a new file, first of all, called AI.tsx. This is a server-only component. And it's very important that we add a server at the top. Now we can export const AI. And this will create a context for us. And in the context, we have some actions. We'll talk about what those are. They're literally what they sound like. And we have AI state and UI state. So initial AI state, initial UI state. And these are just arrays of conversations. And the conversations look like, you know, they look like there's a role, which is, you know, user or assistant.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Building a Voice-Enabled AI Assistant With Javascript
JSNation 2023JSNation 2023
21 min
Building a Voice-Enabled AI Assistant With Javascript
Top Content
This Talk discusses building a voice-activated AI assistant using web APIs and JavaScript. It covers using the Web Speech API for speech recognition and the speech synthesis API for text to speech. The speaker demonstrates how to communicate with the Open AI API and handle the response. The Talk also explores enabling speech recognition and addressing the user. The speaker concludes by mentioning the possibility of creating a product out of the project and using Tauri for native desktop-like experiences.
AI and Web Development: Hype or Reality
JSNation 2023JSNation 2023
24 min
AI and Web Development: Hype or Reality
Top Content
This talk explores the use of AI in web development, including tools like GitHub Copilot and Fig for CLI commands. AI can generate boilerplate code, provide context-aware solutions, and generate dummy data. It can also assist with CSS selectors and regexes, and be integrated into applications. AI is used to enhance the podcast experience by transcribing episodes and providing JSON data. The talk also discusses formatting AI output, crafting requests, and analyzing embeddings for similarity.
The Rise of the AI Engineer
React Summit US 2023React Summit US 2023
30 min
The Rise of the AI Engineer
Watch video: The Rise of the AI Engineer
The rise of AI engineers is driven by the demand for AI and the emergence of ML research and engineering organizations. Start-ups are leveraging AI through APIs, resulting in a time-to-market advantage. The future of AI engineering holds promising results, with a focus on AI UX and the role of AI agents. Equity in AI and the central problems of AI engineering require collective efforts to address. The day-to-day life of an AI engineer involves working on products or infrastructure and dealing with specialties and tools specific to the field.
Web Apps of the Future With Web AI
JSNation 2024JSNation 2024
32 min
Web Apps of the Future With Web AI
Web AI in JavaScript allows for running machine learning models client-side in a web browser, offering advantages such as privacy, offline capabilities, low latency, and cost savings. Various AI models can be used for tasks like background blur, text toxicity detection, 3D data extraction, face mesh recognition, hand tracking, pose detection, and body segmentation. JavaScript libraries like MediaPipe LLM inference API and Visual Blocks facilitate the use of AI models. Web AI is in its early stages but has the potential to revolutionize web experiences and improve accessibility.
Case Study: Building Accessible Reusable React Components at GitHub
React Summit 2024React Summit 2024
29 min
Case Study: Building Accessible Reusable React Components at GitHub
The talk discusses building accessible React components and emphasizes the importance of using the correct HTML elements and ARIA roles for accessibility. It explains how to navigate and select options within a form and how to add supplementary text using Aria described by. The speaker also discusses the benefits of using conditional checkboxes and ARIA disabled to improve the UI. Additionally, the talk explores the role of JavaScript in web accessibility and provides recommendations for testing website accessibility.
Code coverage with AI
TestJS Summit 2023TestJS Summit 2023
8 min
Code coverage with AI
Codium is a generative AI assistant for software development that offers code explanation, test generation, and collaboration features. It can generate tests for a GraphQL API in VS Code, improve code coverage, and even document tests. Codium allows analyzing specific code lines, generating tests based on existing ones, and answering code-related questions. It can also provide suggestions for code improvement, help with code refactoring, and assist with writing commit messages.

Workshops on related topic

AI on Demand: Serverless AI
DevOps.js Conf 2024DevOps.js Conf 2024
163 min
AI on Demand: Serverless AI
Top Content
Featured WorkshopFree
Nathan Disidore
Nathan Disidore
In this workshop, we discuss the merits of serverless architecture and how it can be applied to the AI space. We'll explore options around building serverless RAG applications for a more lambda-esque approach to AI. Next, we'll get hands on and build a sample CRUD app that allows you to store information and query it using an LLM with Workers AI, Vectorize, D1, and Cloudflare Workers.
Leveraging LLMs to Build Intuitive AI Experiences With JavaScript
JSNation 2024JSNation 2024
108 min
Leveraging LLMs to Build Intuitive AI Experiences With JavaScript
Featured Workshop
Roy Derks
Shivay Lamba
2 authors
Today every developer is using LLMs in different forms and shapes, from ChatGPT to code assistants like GitHub CoPilot. Following this, lots of products have introduced embedded AI capabilities, and in this workshop we will make LLMs understandable for web developers. And we'll get into coding your own AI-driven application. No prior experience in working with LLMs or machine learning is needed. Instead, we'll use web technologies such as JavaScript, React which you already know and love while also learning about some new libraries like OpenAI, Transformers.js
Llms Workshop: What They Are and How to Leverage Them
React Summit 2024React Summit 2024
66 min
Llms Workshop: What They Are and How to Leverage Them
Featured Workshop
Nathan Marrs
Haris Rozajac
2 authors
Join Nathan in this hands-on session where you will first learn at a high level what large language models (LLMs) are and how they work. Then dive into an interactive coding exercise where you will implement LLM functionality into a basic example application. During this exercise you will get a feel for key skills for working with LLMs in your own applications such as prompt engineering and exposure to OpenAI's API.
After this session you will have insights around what LLMs are and how they can practically be used to improve your own applications.
Table of contents: - Interactive demo implementing basic LLM powered features in a demo app- Discuss how to decide where to leverage LLMs in a product- Lessons learned around integrating with OpenAI / overview of OpenAI API- Best practices for prompt engineering- Common challenges specific to React (state management :D / good UX practices)
Working With OpenAI and Prompt Engineering for React Developers
React Advanced 2023React Advanced 2023
98 min
Working With OpenAI and Prompt Engineering for React Developers
Top Content
Workshop
Richard Moss
Richard Moss
In this workshop we'll take a tour of applied AI from the perspective of front end developers, zooming in on the emerging best practices when it comes to working with LLMs to build great products. This workshop is based on learnings from working with the OpenAI API from its debut last November to build out a working MVP which became PowerModeAI (A customer facing ideation and slide creation tool).
In the workshop they'll be a mix of presentation and hands on exercises to cover topics including:
- GPT fundamentals- Pitfalls of LLMs- Prompt engineering best practices and techniques- Using the playground effectively- Installing and configuring the OpenAI SDK- Approaches to working with the API and prompt management- Implementing the API to build an AI powered customer facing application- Fine tuning and embeddings- Emerging best practice on LLMOps
Hands-on with AG Grid's React Data Grid
React Summit 2022React Summit 2022
147 min
Hands-on with AG Grid's React Data Grid
Top Content
WorkshopFree
Sean Landsman
Sean Landsman
Get started with AG Grid React Data Grid with a hands-on tutorial from the core team that will take you through the steps of creating your first grid, including how to configure the grid with simple properties and custom components. AG Grid community edition is completely free to use in commercial applications, so you'll learn a powerful tool that you can immediately add to your projects. You'll also discover how to load data into the grid and different ways to add custom rendering to the grid. By the end of the workshop, you will have created an AG Grid React Data Grid and customized with functional React components.- Getting started and installing AG Grid- Configuring sorting, filtering, pagination- Loading data into the grid- The grid API- Using hooks and functional components with AG Grid- Capabilities of the free community edition of AG Grid- Customizing the grid with React Components
Building AI Applications for the Web
React Day Berlin 2023React Day Berlin 2023
98 min
Building AI Applications for the Web
Workshop
Roy Derks
Roy Derks
Today every developer is using LLMs in different forms and shapes. Lots of products have introduced embedded AI capabilities, and in this workshop you’ll learn how to build your own AI application. No experience in building LLMs or machine learning is needed. Instead, we’ll use web technologies such as JavaScript, React and GraphQL which you already know and love.