mirror of
https://github.com/run-llama/chat-ui.git
synced 2026-07-01 21:24:01 -04:00
1.4 KiB
1.4 KiB
Next.js Chat UI Example
This is a simple Next.js application demonstrating how to use the @llamaindex/chat-ui library to build a chat interface.
Features
- Basic chat interface using
@llamaindex/chat-uicomponents - API route that integrates with LlamaIndex and OpenAI
- Fallback to fake streaming when API key is not available
- TypeScript support
Getting Started
-
Install dependencies:
npm install -
Set your OpenAI API key:
export OPENAI_API_KEY=your-api-key-here -
Start the development server:
npm run dev -
Open http://localhost:3000 in your browser.
Project Structure
app/page.tsx- Main chat interfaceapp/layout.tsx- Root layoutapp/api/chat/route.ts- Chat API endpoint using LlamaIndexpackage.json- Dependencies and scriptsnext.config.js- Next.js configurationtsconfig.json- TypeScript configuration
How It Works
The example uses:
- @llamaindex/chat-ui components for the UI
- LlamaIndex SimpleChatEngine for AI chat functionality
- Vercel AI SDK for streaming responses
- OpenAI GPT-4o-mini as the language model
An OpenAI API key is required for the chat functionality to work.