npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@llamaindex/chat-ui

v0.0.13

Published

Chat UI components for LLM apps

Downloads

6,239

Readme

@llamaindex/chat-ui

Chat UI components for LLM apps

Overview

@llamaindex/chat-ui is a React component library that provides ready-to-use UI elements for building chat interfaces in LLM (Large Language Model) applications. This package is designed to streamline the development of chat-based user interfaces for AI-powered applications.

Installation

To install the package, run the following command in your project directory:

npm install @llamaindex/chat-ui

Features

  • Pre-built chat components (e.g., message bubbles, input fields)
  • Minimal styling, fully customizable with Tailwind CSS
  • Custom widgets to extend components (e.g., for rendering generated or retrieved documents)
  • TypeScript support for type safety
  • Easy integration with LLM backends like Vercel Ai
  • Code and Latex styling with highlight.js and katex

Usage

  1. Install the package
npm install @llamaindex/chat-ui
  1. Configure your tailwind.config.ts to include the chat-ui components
module.exports = {
  content: [
    'app/**/*.{ts,tsx}',
    'node_modules/@llamaindex/chat-ui/**/*.{ts,tsx}',
  ],
  // ...
}
  1. Import the components and use them

The easiest way to get started is to connect the whole ChatSection component with useChat hook from vercel/ai:

import { ChatSection } from '@llamaindex/chat-ui'
import { useChat } from 'ai/react'

const ChatExample = () => {
  const handler = useChat()
  return <ChatSection handler={handler} />
}

This simple example looks like this:

output

Component Composition

Components are designed to be composable. You can use them as is:

import { ChatSection } from '@llamaindex/chat-ui'
import { useChat } from 'ai/react'

const ChatExample = () => {
  const handler = useChat()
  return <ChatSection handler={handler} />
}

Or you can extend them with your own children components:

import { ChatSection, ChatMessages, ChatInput } from '@llamaindex/chat-ui'
import LlamaCloudSelector from './components/LlamaCloudSelector' // your custom component
import { useChat } from 'ai/react'

const ChatExample = () => {
  const handler = useChat()
  return (
    <ChatSection handler={handler}>
      <ChatMessages />
      <ChatInput>
        <ChatInput.Preview />
        <ChatInput.Form className="bg-lime-500">
          <ChatInput.Field type="textarea" />
          <ChatInput.Upload />
          <LlamaCloudSelector /> {/* custom component */}
          <ChatInput.Submit />
        </ChatInput.Form>
      </ChatInput>
    </ChatSection>
  )
}

Your custom component can use the useChatUI hook to send additional data to the chat API endpoint:

import { useChatInput } from '@llamaindex/chat-ui'

const LlamaCloudSelector = () => {
  const { requestData, setRequestData } = useChatUI()
  return (
    <div>
      <select
        value={requestData?.model}
        onChange={e => setRequestData({ model: e.target.value })}
      >
        <option value="llama-3.1-70b-instruct">Pipeline 1</option>
        <option value="llama-3.1-8b-instruct">Pipeline 2</option>
      </select>
    </div>
  )
}

Styling

Components

chat-ui components are based on shadcn components using Tailwind CSS.

You can override the default styles by changing CSS variables in the globals.css file of your Tailwind CSS configuration. For example, to change the background and foreground colors:

:root {
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
}

For a list of all available CSS variables, please refer to the Shadcn Theme Config.

Additionally, you can also override each component's styles by setting custom classes in the className prop. For example, setting the background color of the ChatInput.Form component:

import { ChatSection, ChatMessages, ChatInput } from '@llamaindex/chat-ui'
import { useChat } from 'ai/react'

const ChatExample = () => {
  const handler = useChat()
  return (
    <ChatSection handler={handler}>
      <ChatMessages />
      <ChatInput>
        <ChatInput.Preview />
        <ChatInput.Form className="bg-lime-500">
          <ChatInput.Field type="textarea" />
          <ChatInput.Upload />
          <ChatInput.Submit />
        </ChatInput.Form>
      </ChatInput>
    </ChatSection>
  )
}

Code and Latex styling

Inside the markdown component, we use highlight.js for code blocks, katex for latex, and pdf-viewer for pdf files. If your app is using code, latex or pdf files, you'll need to import their CSS files:

import '@llamaindex/chat-ui/styles/markdown.css' // code, latex and custom markdown styling
import '@llamaindex/chat-ui/styles/pdf.css' // pdf styling

The code.css file uses the atom-one-dark theme from highlight.js by default. There are a lot of others to choose from: https://highlightjs.org/demo You can use any of them by copying their CSS to your project and importing it.

Example

See the example app for a complete example. The generate a full-featured project to get started with, use create-llama.

License

@llamaindex/chat-ui is released under the MIT License.

Support

If you encounter any issues or have questions, please file an issue on our GitHub repository.