Generative UI with Structured output from LLMs

Pushkar Yadav

June 1, 2024


Creating UI with LLMs is both fun and challenging. The key is to tackle hallucinations and ensure the output is structured and usable. I've developed a project called UI-G that generates UI components based on input text.

UI-G works by taking user input and generating UI components using GPT-4o (demo version) or Gemini 1.5 Pro, which have minimal hallucinations. The output is validated with Zod to ensure proper structure. If everything checks out, it sends back the element code, and the UI rendering process proceeds smoothly.

Maintaining UI context is crucial, as users might need to change the color of a button or the size of a specific element while keeping everything consistent.

What's Next? This is base of what is possible with structured output with llm and how it can be used in real world. I will also be implementing Returning JSX from a custom trained RAG in future which will be much better and faster.

This did not had much code it's more of a concept, have attached 2 files page.js and action.js into this gist which can be easily placed inside a Next Js 14 project.Avalable here: Github Gist Link also attaching first release tweet below.

馃憟 Labs