rioloc/lightspeed-reference-ui

โ˜… 0Forks 0GitHub โ†—Compare

README

Lightspeed Chatbot Reference UI

A reference implementation of a chatbot interface built with React, TypeScript, and PatternFly. This project demonstrates how to integrate AI-powered conversational interfaces with modern web applications using the PatternFly design system.

โœจ Features

  • ๐Ÿค– AI-Powered Chat: Interactive chatbot with streaming responses
  • ๐Ÿ”ง Tool Execution: Visual feedback for AI tool usage and execution
  • ๐Ÿ“ฑ Multiple Display Modes: Overlay, docked, and fullscreen modes
  • ๐Ÿ”„ Model Selection: Choose from available AI models
  • ๐Ÿ“š Conversation History: Persistent chat sessions with search
  • โ™ฟ Accessibility: Full screen reader support and keyboard navigation
  • ๐ŸŽจ PatternFly Design: Modern, consistent UI components
  • ๐Ÿ“ฑ Responsive: Works on desktop and mobile devices

๐Ÿš€ Quick Start

Prerequisites: Ensure the lightspeed-stack is running to provide the backend API services.

If you need help getting lightspeed-stack running follow this guide.

git clone https://github.com/your-org/lightspeed-reference-ui
cd lightspeed-reference-ui
npm install && npm run start:dev

The application will be available at http://localhost:9000

๐Ÿ“‹ Development Scripts

# Install development/build dependencies
npm install

# Start the development server
npm run start:dev

# Run a production build (outputs to "dist" dir)
npm run build

# Run the test suite
npm run test

# Run the test suite with coverage
npm run test:coverage

# Run the linter
npm run lint

# Run the code formatter
npm run format

# Launch a tool to inspect the bundle size
npm run bundle-profile:analyze

# Start the express server (run a production build first)
npm run start

๐Ÿ—๏ธ Project Structure

src/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ LightspeedChatbot/           # Main chatbot module
โ”‚   โ”‚   โ”œโ”€โ”€ LightspeedChatbot.tsx    # Main chatbot component
โ”‚   โ”‚   โ”œโ”€โ”€ components/              # Reusable components
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ToolExecutionCards.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/                   # Custom React hooks
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ useChatbot.ts
โ”‚   โ”‚   โ”œโ”€โ”€ services/                # API service layer
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ api.ts
โ”‚   โ”‚   โ”œโ”€โ”€ utils/                   # Helper functions
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ helpers.ts
โ”‚   โ”‚   โ”œโ”€โ”€ types.ts                 # TypeScript definitions
โ”‚   โ”‚   โ””โ”€โ”€ constants.ts             # Configuration constants
โ”‚   โ””โ”€โ”€ utils/                       # Shared utilities
โ”‚       โ””โ”€โ”€ useDocumentTitle.ts
โ”œโ”€โ”€ index.html                       # HTML template
โ””โ”€โ”€ index.tsx                        # Application entry point

๐Ÿ”ง Configuration

API Integration

The chatbot connects to a backend API that should provide:

  • GET /v1/models - Available AI models
  • POST /v1/query - Send chat messages
  • POST /v1/streaming_query - Streaming chat responses

Customization

Update src/app/LightspeedChatbot/constants.ts to configure:

  • API_BASE_URL: Backend API endpoint (default: http://localhost:8080)
  • DEFAULT_SYSTEM_PROMPT: AI behavior instructions
  • USER_AVATAR, BOT_AVATAR: Avatar URLs for chat participants
  • FOOTNOTE_PROPS: Footer disclaimer configuration

๐ŸŽฏ Key Components

LightspeedChatbot

The main chatbot interface that provides:

  • Chat message display with streaming
  • Model selection dropdown
  • Display mode switching (overlay/docked/fullscreen)
  • Conversation history with search
  • Tool execution visualization

ToolExecutionCards

Displays active tool executions during AI processing:

  • Shows tool names and status
  • Provides visual feedback for long-running operations
  • Automatically updates as tools complete

useChatbot Hook

Custom React hook that manages:

  • Chat state and message history
  • API communication and streaming
  • UI state (visibility, display modes)
  • Model selection and loading

๐Ÿ”Œ API Integration

The chatbot expects a backend API with these endpoints:

// Get available models
GET /v1/models
Response: {
  models: Array<{
    identifier: string;
    metadata: Record<string, any>;
    api_model_type: string;
    provider_id: string;
    provider_resource_id: string;
    type: string;
    model_type: string;
  }>
}

// Send query (non-streaming)
POST /v1/query
Body: {
  query: string;
  conversation_id?: string;
  provider?: string;
  model?: string;
  system_prompt?: string;
  attachments?: Array<{
    attachment_type: string;
    content_type: string;
    content: string;
  }>;
}

// Send streaming query
POST /v1/streaming_query
Body: {
  query: string;
  conversation_id?: string;
  provider?: string;
  model?: string;
  system_prompt?: string;
  attachments?: Array<{
    attachment_type: string;
    content_type: string;
    content: string;
  }>;
}
Response: Server-Sent Events stream with events:
- start: { conversation_id: string }
- token: { id: number, role: string, token: string }
- tool_call: { id: number, role: string, token: string | Record<string, any> }
- end: { referenced_documents: any[], truncated: any, input_tokens: number, output_tokens: number }

๐Ÿ“ฑ Usage Examples

Basic Integration

import { LightspeedChatbot } from './app/LightspeedChatbot';

function App() {
  return (
    <div className="app">
      <main>
        {/* Your app content */}
      </main>
      <LightspeedChatbot />
    </div>
  );
}

๐Ÿงช Testing

The project includes comprehensive tests:

# Run all tests
npm run test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

๐Ÿ“ฆ Building

# Production build
npm run build

# Analyze bundle size
npm run bundle-profile:analyze

๐Ÿ”ง Development Tools

  • TypeScript: Type safety and better development experience
  • ESLint: Code linting and style enforcement
  • Prettier: Code formatting
  • Jest: Unit testing framework
  • React Testing Library: Component testing utilities
  • Webpack: Module bundling and development server

๐ŸŒ Browser Support

This application supports modern browsers with ES6+ features:

  • Chrome 88+
  • Firefox 85+
  • Safari 14+
  • Edge 88+

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

If you encounter any issues or have questions:

  • Check the Issues page
  • Review the component documentation in src/app/LightspeedChatbot/README.md
  • Refer to the PatternFly documentation for UI components

Contributors

jrobertboosbparees

Issues