A flexible React component for text selection and AI chat integration. This package provides an easy way to integrate text selection and AI-powered chat capabilities into your application.
- 🔍 Text Selection: Select text anywhere on your page and discuss it with an AI assistant
- 🖼️ Image Support:
- Paste images directly into the chat input
- Select images on the page to include in the selection context
- 🔄 Multiple LLM Providers: Support for OpenAI, Gemini, Claude, and custom providers
- 🎨 Theming: Light/dark mode and customizable themes
- 📱 Responsive: Works across desktop and mobile
- 🧩 Modular Design: Use individual components or the full chat interface
# Install the package
npm install llm-select-and-chat
# Install peer dependencies (if not already in your project)
npm install react react-dom styled-componentsimport React from 'react';
import { SelectChat } from 'llm-select-and-chat';
function App() {
return (
<div style={{ height: '600px', width: '400px' }}>
<SelectChat
apiKey="your-openai-api-key"
theme="light"
/>
</div>
);
}import React from 'react';
import { SelectChat, createTheme, ThemeProvider } from 'llm-select-and-chat';
function App() {
const customTheme = createTheme('light');
customTheme.colors.primary = '#4a90e2';
return (
<ThemeProvider theme={customTheme}>
<SelectChat apiKey="your-api-key" />
</ThemeProvider>
);
}The component supports two ways of working with images:
Paste images directly from clipboard:
- Copy an image to your clipboard (e.g., take a screenshot)
- Click on the chat input field
- Paste using Ctrl+V / Cmd+V
- Send with or without an accompanying text message
You can also select images on the page to include in the selection context:
import { SelectChat, SelectableImage } from 'llm-select-and-chat';
function App() {
return (
<div>
<div>
<p>Select this text and click an image below to include both in your selection.</p>
<div style={{ display: 'flex', gap: '10px' }}>
<SelectableImage src="/image1.jpg" alt="Selectable image 1" />
<SelectableImage src="/image2.jpg" alt="Selectable image 2" />
</div>
</div>
<SelectChat apiKey="your-api-key" />
</div>
);
}Images are automatically rendered in the selection context, allowing the AI to discuss both the selected text and images together.
When text is selected, the component captures context around the selection and makes it available to the AI assistant.
By default, the component only captures the immediate context around the selection. If you need the AI to have access to the entire document, you can enable full document extraction:
<SelectChat
apiKey="your-openai-api-key"
extractFullDocument={true}
/>With full document extraction enabled, the complete text content of the page will be included with each selection, giving the AI assistant more comprehensive context.
For complete documentation, including advanced usage and API reference, see:
The library comes with several examples to help you get started:
# Clone the repository
git clone https://github.com/username/llm-select-and-chat.git
cd llm-select-and-chat
# Install dependencies and build the library
npm install
npm run build
# Install example dependencies
cd examples
npm install
# Start the example server
npm startThen open your browser to http://localhost:3000/examples/
- Basic Example: Minimal implementation with default styling
- Simple Integration: Integration into an existing webpage
- React Integration: Usage within a React application
Each example demonstrates different aspects of the library, including custom styling, provider selection, and image handling.
MIT © [Your Name]