Chat With Your Components

Rate this content
Bookmark

How many times have you done this: Made an API, used the data with React, and then started over, again and again? What if we could make a full stack React application that can create user interfaces on its own, without needing to write any backend code and directly chat with your data? In this talk, we'll learn how to make an app that can change the way data looks using simple text commands and smart AI changes. Let's talk with your components.

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

FAQ

Proxima is an open source analytics platform developed by Teodor, a web developer.

AI packets allow direct interaction with AI models from React components, enabling prompt-based responses and advanced UI capabilities using OpenAI and other model providers.

Chat2BT reintroduces the chat interface as a straightforward way to interact with AI, decoupling end users from developers' release cycles and enabling dynamic UI interactions.

React and AI can be used to build smart user interfaces by leveraging components that function like Lego bricks, allowing for flexible data integration, content generation, and seamless UI updates.

LangChain is an open-source framework that facilitates interaction with data sources and models, enabling dynamic SQL query generation and UI component creation based on user inputs.

Challenges include ensuring the model produces correct outputs for various scenarios, managing data mapping to user intentions, and maintaining visual consistency across different screens.

Zod Schemas provide a runtime schema to guide AI models, ensuring accurate output generation and enabling features like form pre-filling, data validation, and dynamic UI adjustments.

AI can generate weather-related UI components by instructing the model to act as a weather assistant, using prompts and context to produce dynamic weather data representations.

The AI package integrates with prompt engineering by using structured prompts to guide model outputs, enabling the creation of generative components for diverse applications.

Detailed information and examples from Teodor's talk can be found on his website, where he has published articles with use cases and code demos.

Theodore Vorillas
Theodore Vorillas
15 min
28 Oct, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
In this Talk, the speaker discusses how to build smart user interfaces using React and AI. They explore using AI to enhance data interaction in a table component and demonstrate how AI can be used to pre-fill calendar slots in a booking engine. The speaker also explains how to create dynamic UIs with React by adjusting language prompts and specifying UI elements. They introduce LangChain, an open-source framework for building language model applications, and explain how it can be used to generate UIs. The speaker concludes by discussing how JSON data can be used to generate UIs and provides documentation and examples for building UI components.
Available in Español: Chat With Your Components

1. Building Smart User Interfaces with React and AI

Short description:

In my talk, I'll explain how to build smart user interfaces using React and AI. React has revolutionized web development with its powerful and flexible component system. The chat interface allows for straightforward interaction with AI. We'll experiment with AI packets, which enable direct interaction with AI models. Using Zod Schemas, we can guide the models to produce the correct output.

Hi. I hope you're enjoying the conference so far. My name is Teodor. I'm a web developer building Proxima, an open source analytics platform. In my talk today, I'll try to explain how you can build smart user interfaces using React and artificial intelligence.

In my honest opinion, React has been a game changer for web development. JSX index allowed us to repurpose the way we build user interfaces. Imagine you have a bunch of components in the design system. These components are like Lego bricks, but way more powerful and flexible. A component can fit data, generate content, and pass down the result to other components. Then you can start building using these primitives and compose them to build complex user interfaces.

But there's a fundamental problem. Every single time you build something, well, you have to actually write the code, right? Every time you want to make a change, you have to combine the data, the UI, and the logic. So, the end users are somehow tightly coupled with their release cycles of the developers. When chat2BT came out, though, it reintroduced an idea coming from the early 2000s. The chat interface. A symbol and so common user experience. Asking questions and getting answers back in plain text, it's the most straight forward way to interact with artificial intelligence. With the public release of new AI APIs, access to advanced technology became more open, allowing us to create applications that push beyond typical limits.

For this talk, we'll try to experiment a bit with the AI packets. This is a thin wrapper around open AI and other model providers along with some helpers, hooks, and abstractions built on top of React and the Node.js ecosystem. The AI packets allow us to directly interact with AI models from our React components or API routes. So, we can pass a prompt, the desired model, and get a response back in plain text format. And this is just the simplest use case. But there's so much more we can actually do. A model operates like a black box. It has no understanding of your application's context or the data at hand. However, we can guide it by providing a runtime schema to ensure it produces the correct output. For this purpose, we're going to use Zod Schemas. And as an example, we can start exploring how we can solve common user interface problems.

2. Enhancing Data Interaction with AI

Short description:

We explore using AI to tackle the issue of interacting with data in a table component. Streaming the response as a partial object allows for instant UI updates. Zod schema can be used for form validation and data validation. Another example is a booking engine that pre-fills the calendar slot based on the prompt. The AI package integrates full-prompt engineering with generative components. We'll create a weather application called Breeze using an engine to guide the model's output.

Here, we've got a table component alongside a few dropdowns for filtering the data. While the dropdown seems to guide the user, interacting with the data isn't as straightforward as it should be. In larger applications, this could lead to unnecessary clicks and visual clutter.

Now, let's explore how we can tackle this issue using AI. Inside our application, we have our filter schema and use it to generate a filter subject that is passed along the table component. We have just three fields. Category, language, and country. We can pass the schema as context in the model and receive a response.

With the AI SDK, we can stream the response as a partial object, while the schema defines the structure of the data returned by the model. Streaming is a powerful feature, allowing us to update the UI almost instantly. Finally, we set up a basic input to trigger the filtering process. It's important to note that in frameworks like Next.js, we can fully take advantage of the stream capabilities of React Server components.

And this is what the implementation looks like in the user interface. We can gradually add more fields. And as the schema updates, the interface will adapt accordingly.

Now, if you are anyhow familiar with Zod, you may have used it to validate form inputs as well. We can build on top of the previous example by pre-filling a form directly from the model's response. The source of the data isn't crucial, as it can be passed through the context of the generation. The best part is that we can reuse the same Zod schema for the AI generation, front-end form validation, and back-end data validation as well.

Finally, here's another example that I really like, and that's a booking engine. Once the prompt is injected with the correct context, we can pre-fill the slot in the calendar and generate the event accordingly. Everything is starting in the front-end. All the previous demos highlighted micro-indirections and how we can address common UI challenges, such as filtering, completing complex forms, or managing date pickers. If you want to dive deeper into this topic, I have written a detailed article on my website for you to explore.

And actually, this was just a glimpse of what we can achieve with a large language model. Undeniably, the most powerful aspect of the AI package is its ability to integrate full-prompt engineering with generative components. So, we'll try to create a simple weather application that lets us check the weather in different cities around the world. Let's call it Breeze. The most crucial part is to start creating the engine that will guide the model to produce the correct output. In this case, we are simply instructing the model to act as a weather 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.
The Ai-Assisted Developer Workflow: Build Faster and Smarter Today
JSNation US 2024JSNation US 2024
31 min
The Ai-Assisted Developer Workflow: Build Faster and Smarter Today
AI is transforming software engineering by using agents to help with coding. Agents can autonomously complete tasks and make decisions based on data. Collaborative AI and automation are opening new possibilities in code generation. Bolt is a powerful tool for troubleshooting, bug fixing, and authentication. Code generation tools like Copilot and Cursor provide support for selecting models and codebase awareness. Cline is a useful extension for website inspection and testing. Guidelines for coding with agents include defining requirements, choosing the right model, and frequent testing. Clear and concise instructions are crucial in AI-generated code. Experienced engineers are still necessary in understanding architecture and problem-solving. Energy consumption insights and sustainability are discussed in the Talk.
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.
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.
AI for React Developers
React Advanced 2024React Advanced 2024
142 min
AI for React Developers
Featured Workshop
Eve Porcello
Eve Porcello
Knowledge of AI tooling is critical for future-proofing the careers of React developers, and the Vercel suite of AI tools is an approachable on-ramp. In this course, we’ll take a closer look at the Vercel AI SDK and how this can help React developers build streaming interfaces with JavaScript and Next.js. We’ll also incorporate additional 3rd party APIs to build and deploy a music visualization app.
Topics:- Creating a React Project with Next.js- Choosing a LLM- Customizing Streaming Interfaces- Building Routes- Creating and Generating Components - Using Hooks (useChat, useCompletion, useActions, etc)
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
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.