our friendly logo that looks like a hashbrown character from an animated tv showhashbrown

@hashbrownai/reactuseUiChat

This React hook creates a chat instance that can generate and render UI components. The result object contains functions and state enabling you to send and receive messages and monitor the state of the chat.

The useUiChat hook provides functionality for generating UI components through chat. This is particularly useful for: - Dynamic UI generation - Interactive chat interfaces - Component-based responses - Building chat-based UIs

useUiChat: <Tools extends Chat.AnyTool>(options: UiChatOptions<Tools>) => {
    messages: UiChatMessage<Tools>[];
    setComponents: React.Dispatch<React.SetStateAction<ExposedComponent<any>[]>>;
    setMessages: (messages: Chat.Message<UiChatSchema, Tools>[]) => void;
    sendMessage: (message: Chat.Message<UiChatSchema, Tools>) => void;
    resendMessages: () => void;
    reload: () => void;
    error: Error | null;
    isReceiving: boolean;
    isSending: boolean;
    isRunningToolCalls: boolean;
    exhaustedRetries: boolean;
}
@paramoptions
UiChatOptions<Tools>
@typeTools
Chat.AnyTool
@returns
{UseUiChatResult} An object containing chat state, functions to interact with the chat, and rendered UI components.
{
    messages: UiChatMessage<Tools>[];
    setComponents: React.Dispatch<React.SetStateAction<ExposedComponent<any>[]>>;
    setMessages: (messages: Chat.Message<UiChatSchema, Tools>[]) => void;
    sendMessage: (message: Chat.Message<UiChatSchema, Tools>) => void;
    resendMessages: () => void;
    reload: () => void;
    error: Error | null;
    isReceiving: boolean;
    isSending: boolean;
    isRunningToolCalls: boolean;
    exhaustedRetries: boolean;
}

Examples

In this example, the LLM will respond with a UI component that can be rendered directly in your React application.

const { messages, sendMessage } = useUiChat({
  model: 'gpt-4o',
  system: 'You are a helpful assistant that can generate UI components.',
  components: [
    exposeComponent(Button, {
      name: 'Button',
      description: 'A clickable button component',
      props: {
        label: s.string('The text to display on the button'),
        onClick: s.function('Function to call when clicked')
      }
    })
  ]
});

LiveLoveApp provides secure, compliant, and reliable long-term support to enterprises. We are a group of engineers who are passionate about open source.

Enterprise Support

AI Engineering Sprint

Get your team up-to-speed on AI engineering with a one week AI engineering sprint. Includes a workshop on AI engineering with hashbrown and a few days with the hashbrown developer team to bring your AI ideas to life.

Long Term Support

Keep your hashbrown deployments running at peak performance with our Long Term Support. Includes an ongoing support retainer for direct access to the hashbrown developer team, SLA-backed issue resolution, and guided upgrades.

Consulting

LiveLoveApp provides hands-on engagement with our AI engineers for architecture reviews, custom integrations, proof-of-concept builds, performance tuning, and expert guidance on best practices.