|
1 | | -# Patternfly Seed |
| 1 | +# Lightspeed Chatbot Reference UI |
2 | 2 |
|
3 | | -Patternfly Seed is an open source build scaffolding utility for web apps. The primary purpose of this project is to give developers a jump start when creating new projects that will use patternfly. A secondary purpose of this project is to serve as a reference for how to configure various aspects of an application that uses patternfly, webpack, react, typescript, etc. |
| 3 | +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. |
4 | 4 |
|
5 | | -Out of the box you'll get an app layout with chrome (header/sidebar), routing, build pipeline, test suite, and some code quality tools. Basically, all the essentials. |
| 5 | +## ✨ Features |
6 | 6 |
|
7 | | -<img width="1058" alt="Out of box dashboard view of patternfly seed" src="https://github.com/user-attachments/assets/0227b366-67f1-4df8-8d92-e8e95d6e08b3" /> |
| 7 | +- **🤖 AI-Powered Chat**: Interactive chatbot with streaming responses |
| 8 | +- **🔧 Tool Execution**: Visual feedback for AI tool usage and execution |
| 9 | +- **📱 Multiple Display Modes**: Overlay, docked, and fullscreen modes |
| 10 | +- **🔄 Model Selection**: Choose from available AI models |
| 11 | +- **📚 Conversation History**: Persistent chat sessions with search |
| 12 | +- **♿ Accessibility**: Full screen reader support and keyboard navigation |
| 13 | +- **🎨 PatternFly Design**: Modern, consistent UI components |
| 14 | +- **📱 Responsive**: Works on desktop and mobile devices |
8 | 15 |
|
9 | | -## Quick-start |
| 16 | +## 🚀 Quick Start |
10 | 17 |
|
11 | 18 | ```bash |
12 | | -git clone https://github.com/patternfly/patternfly-react-seed |
13 | | -cd patternfly-react-seed |
| 19 | +git clone https://github.com/your-org/lightspeed-reference-ui |
| 20 | +cd lightspeed-reference-ui |
14 | 21 | npm install && npm run start:dev |
15 | 22 | ``` |
16 | | -## Development scripts |
| 23 | + |
| 24 | +The application will be available at `http://localhost:8080` |
| 25 | + |
| 26 | +## 📋 Development Scripts |
| 27 | + |
17 | 28 | ```sh |
18 | 29 | # Install development/build dependencies |
19 | 30 | npm install |
@@ -43,61 +54,197 @@ npm run bundle-profile:analyze |
43 | 54 | npm run start |
44 | 55 | ``` |
45 | 56 |
|
46 | | -## Configurations |
47 | | -* [TypeScript Config](./tsconfig.json) |
48 | | -* [Webpack Config](./webpack.common.js) |
49 | | -* [Jest Config](./jest.config.js) |
50 | | -* [Editor Config](./.editorconfig) |
| 57 | +## 🏗️ Project Structure |
51 | 58 |
|
52 | | -## Raster image support |
| 59 | +``` |
| 60 | +src/ |
| 61 | +├── app/ |
| 62 | +│ ├── LightspeedChatbot/ # Main chatbot module |
| 63 | +│ │ ├── LightspeedChatbot.tsx # Main chatbot component |
| 64 | +│ │ ├── components/ # Reusable components |
| 65 | +│ │ │ └── ToolExecutionCards.tsx |
| 66 | +│ │ ├── hooks/ # Custom React hooks |
| 67 | +│ │ │ └── useChatbot.ts |
| 68 | +│ │ ├── services/ # API service layer |
| 69 | +│ │ │ └── api.ts |
| 70 | +│ │ ├── utils/ # Helper functions |
| 71 | +│ │ │ └── helpers.ts |
| 72 | +│ │ ├── types.ts # TypeScript definitions |
| 73 | +│ │ └── constants.ts # Configuration constants |
| 74 | +│ └── utils/ # Shared utilities |
| 75 | +│ └── useDocumentTitle.ts |
| 76 | +├── index.html # HTML template |
| 77 | +└── index.tsx # Application entry point |
| 78 | +``` |
53 | 79 |
|
54 | | -To use an image asset that's shipped with PatternFly core, you'll prefix the paths with "@assets". `@assets` is an alias for the PatternFly assets directory in node_modules. |
| 80 | +## 🔧 Configuration |
| 81 | + |
| 82 | +### API Integration |
| 83 | +The chatbot connects to a backend API that should provide: |
| 84 | +- `GET /v1/models` - Available AI models |
| 85 | +- `POST /v1/query` - Send chat messages |
| 86 | +- `POST /v1/streaming_query` - Streaming chat responses |
| 87 | + |
| 88 | +### Customization |
| 89 | +Update `src/app/LightspeedChatbot/constants.ts` to configure: |
| 90 | +- `API_BASE_URL`: Backend API endpoint (default: `http://localhost:8080`) |
| 91 | +- `DEFAULT_SYSTEM_PROMPT`: AI behavior instructions |
| 92 | +- `USER_AVATAR`, `BOT_AVATAR`: Avatar URLs for chat participants |
| 93 | +- `FOOTNOTE_PROPS`: Footer disclaimer configuration |
| 94 | + |
| 95 | +## 🎯 Key Components |
| 96 | + |
| 97 | +### LightspeedChatbot |
| 98 | +The main chatbot interface that provides: |
| 99 | +- Chat message display with streaming |
| 100 | +- Model selection dropdown |
| 101 | +- Display mode switching (overlay/docked/fullscreen) |
| 102 | +- Conversation history with search |
| 103 | +- Tool execution visualization |
| 104 | + |
| 105 | +### ToolExecutionCards |
| 106 | +Displays active tool executions during AI processing: |
| 107 | +- Shows tool names and status |
| 108 | +- Provides visual feedback for long-running operations |
| 109 | +- Automatically updates as tools complete |
| 110 | + |
| 111 | +### useChatbot Hook |
| 112 | +Custom React hook that manages: |
| 113 | +- Chat state and message history |
| 114 | +- API communication and streaming |
| 115 | +- UI state (visibility, display modes) |
| 116 | +- Model selection and loading |
| 117 | + |
| 118 | +## 🔌 API Integration |
| 119 | + |
| 120 | +The chatbot expects a backend API with these endpoints: |
| 121 | + |
| 122 | +```typescript |
| 123 | +// Get available models |
| 124 | +GET /v1/models |
| 125 | +Response: { |
| 126 | + models: Array<{ |
| 127 | + identifier: string; |
| 128 | + metadata: Record<string, any>; |
| 129 | + api_model_type: string; |
| 130 | + provider_id: string; |
| 131 | + provider_resource_id: string; |
| 132 | + type: string; |
| 133 | + model_type: string; |
| 134 | + }> |
| 135 | +} |
55 | 136 |
|
56 | | -For example: |
57 | | -```js |
58 | | -import imgSrc from '@assets/images/g_sizing.png'; |
59 | | -<img src={imgSrc} alt="Some image" /> |
60 | | -``` |
| 137 | +// Send query (non-streaming) |
| 138 | +POST /v1/query |
| 139 | +Body: { |
| 140 | + query: string; |
| 141 | + conversation_id?: string; |
| 142 | + provider?: string; |
| 143 | + model?: string; |
| 144 | + system_prompt?: string; |
| 145 | + attachments?: Array<{ |
| 146 | + attachment_type: string; |
| 147 | + content_type: string; |
| 148 | + content: string; |
| 149 | + }>; |
| 150 | +} |
61 | 151 |
|
62 | | -You can use a similar technique to import assets from your local app, just prefix the paths with "@app". `@app` is an alias for the main src/app directory. |
| 152 | +// Send streaming query |
| 153 | +POST /v1/streaming_query |
| 154 | +Body: { |
| 155 | + query: string; |
| 156 | + conversation_id?: string; |
| 157 | + provider?: string; |
| 158 | + model?: string; |
| 159 | + system_prompt?: string; |
| 160 | + attachments?: Array<{ |
| 161 | + attachment_type: string; |
| 162 | + content_type: string; |
| 163 | + content: string; |
| 164 | + }>; |
| 165 | +} |
| 166 | +Response: Server-Sent Events stream with events: |
| 167 | +- start: { conversation_id: string } |
| 168 | +- token: { id: number, role: string, token: string } |
| 169 | +- end: { referenced_documents: any[], truncated: any, input_tokens: number, output_tokens: number } |
| 170 | +``` |
63 | 171 |
|
64 | | -```js |
65 | | -import loader from '@app/assets/images/loader.gif'; |
66 | | -<img src={loader} alt="Content loading" /> |
| 172 | +## 📱 Usage Examples |
| 173 | + |
| 174 | +### Basic Integration |
| 175 | +```typescript |
| 176 | +import { LightspeedChatbot } from './app/LightspeedChatbot'; |
| 177 | + |
| 178 | +function App() { |
| 179 | + return ( |
| 180 | + <div className="app"> |
| 181 | + <main> |
| 182 | + {/* Your app content */} |
| 183 | + </main> |
| 184 | + <LightspeedChatbot /> |
| 185 | + </div> |
| 186 | + ); |
| 187 | +} |
67 | 188 | ``` |
68 | 189 |
|
69 | | -## Vector image support |
70 | | -Inlining SVG in the app's markup is also possible. |
71 | 190 |
|
72 | | -```js |
73 | | -import logo from '@app/assets/images/logo.svg'; |
74 | | -<span dangerouslySetInnerHTML={{__html: logo}} /> |
| 191 | +## 🧪 Testing |
| 192 | + |
| 193 | +The project includes comprehensive tests: |
| 194 | + |
| 195 | +```bash |
| 196 | +# Run all tests |
| 197 | +npm run test |
| 198 | + |
| 199 | +# Run tests with coverage |
| 200 | +npm run test:coverage |
| 201 | + |
| 202 | +# Run tests in watch mode |
| 203 | +npm run test:watch |
75 | 204 | ``` |
76 | 205 |
|
77 | | -You can also use SVG when applying background images with CSS. To do this, your SVG's must live under a `bgimages` directory (this directory name is configurable in [webpack.common.js](./webpack.common.js#L5)). This is necessary because you may need to use SVG's in several other context (inline images, fonts, icons, etc.) and so we need to be able to differentiate between these usages so the appropriate loader is invoked. |
78 | | -```css |
79 | | -body { |
80 | | - background: url(./assets/bgimages/img_avatar.svg); |
81 | | -} |
| 206 | +## 📦 Building |
| 207 | + |
| 208 | +```bash |
| 209 | +# Production build |
| 210 | +npm run build |
| 211 | + |
| 212 | +# Analyze bundle size |
| 213 | +npm run bundle-profile:analyze |
82 | 214 | ``` |
83 | 215 |
|
84 | | -## Adding custom CSS |
85 | | -When importing CSS from a third-party package for the first time, you may encounter the error `Module parse failed: Unexpected token... You may need an appropriate loader to handle this file typ...`. You need to register the path to the stylesheet directory in [stylePaths.js](./stylePaths.js). We specify these explicitly for performance reasons to avoid webpack needing to crawl through the entire node_modules directory when parsing CSS modules. |
| 216 | +## 🔧 Development Tools |
86 | 217 |
|
87 | | -## Code quality tools |
88 | | -* For accessibility compliance, we use [react-axe](https://github.com/dequelabs/react-axe) |
89 | | -* To keep our bundle size in check, we use [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) |
90 | | -* To keep our code formatting in check, we use [prettier](https://github.com/prettier/prettier) |
91 | | -* To keep our code logic and test coverage in check, we use [jest](https://github.com/facebook/jest) |
92 | | -* To ensure code styles remain consistent, we use [eslint](https://eslint.org/) |
| 218 | +- **TypeScript**: Type safety and better development experience |
| 219 | +- **ESLint**: Code linting and style enforcement |
| 220 | +- **Prettier**: Code formatting |
| 221 | +- **Jest**: Unit testing framework |
| 222 | +- **React Testing Library**: Component testing utilities |
| 223 | +- **Webpack**: Module bundling and development server |
93 | 224 |
|
94 | | -## Multi environment configuration |
95 | | -This project uses [dotenv-webpack](https://www.npmjs.com/package/dotenv-webpack) for exposing environment variables to your code. Either export them at the system level like `export MY_ENV_VAR=http://dev.myendpoint.com && npm run start:dev` or simply drop a `.env` file in the root that contains your key-value pairs like below: |
| 225 | +## 🌐 Browser Support |
96 | 226 |
|
97 | | -```sh |
98 | | -ENV_1=http://1.myendpoint.com |
99 | | -ENV_2=http://2.myendpoint.com |
100 | | -``` |
| 227 | +This application supports modern browsers with ES6+ features: |
| 228 | +- Chrome 88+ |
| 229 | +- Firefox 85+ |
| 230 | +- Safari 14+ |
| 231 | +- Edge 88+ |
| 232 | + |
| 233 | +## 🤝 Contributing |
| 234 | + |
| 235 | +1. Fork the repository |
| 236 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 237 | +3. Commit your changes (`git commit -m 'Add some amazing feature'`) |
| 238 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 239 | +5. Open a Pull Request |
| 240 | + |
| 241 | +## 📄 License |
| 242 | + |
| 243 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
101 | 244 |
|
| 245 | +## 🆘 Support |
102 | 246 |
|
103 | | -With that in place, you can use the values in your code like `console.log(process.env.ENV_1);` |
| 247 | +If you encounter any issues or have questions: |
| 248 | +- Check the [Issues](https://github.com/your-org/lightspeed-reference-ui/issues) page |
| 249 | +- Review the component documentation in `src/app/LightspeedChatbot/README.md` |
| 250 | +- Refer to the [PatternFly documentation](https://www.patternfly.org/get-started/develop) for UI components |
0 commit comments