Skip to content

Commit 064ae61

Browse files
authored
Merge pull request #140 from sourcefuse/automated-docs-sync/loopback4-llm-chat-extension
Sync loopback4-llm-chat-extension Docs
2 parents 1a28043 + 4448a0e commit 064ae61

File tree

1 file changed

+111
-0
lines changed
  • docs/arc-api-docs/extensions/loopback4-llm-chat-extension

1 file changed

+111
-0
lines changed

docs/arc-api-docs/extensions/loopback4-llm-chat-extension/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,117 @@ Users can provide feedback on generated datasets through the dataset actions end
173173

174174
![alt text](https://raw.githubusercontent.com/sourcefuse/llm-chat-component/refs/heads/main/db-query-graph.png)
175175

176+
## VisualizerComponent
177+
178+
The `VisualizerComponent` extends the LLM Chat functionality by providing intelligent data visualization capabilities. This component automatically generates charts and graphs based on database query results, making data insights more accessible and visually appealing.
179+
180+
### Features
181+
182+
- **Automatic Visualization Selection** - The system intelligently selects the most appropriate visualization type based on the data structure and user prompt
183+
- **Multiple Chart Types** - Supports bar charts, line charts, and pie charts out of the box
184+
- **LLM-Powered Configuration** - Uses AI to generate optimal chart configurations including axis selection, orientation, and styling
185+
- **Seamless Integration** - Works directly with datasets generated by the DbQueryComponent
186+
187+
### Available Visualizers
188+
189+
The component includes three built-in visualizers:
190+
191+
#### Bar Chart Visualizer (`src/components/visualization/visualizers/bar.visualizer.ts:13`)
192+
193+
- **Best for**: Comparing values across different categories or showing trends over time
194+
- **Configuration**: Automatically determines category column (x-axis) and value column (y-axis)
195+
- **Options**: Supports both vertical and horizontal orientations
196+
197+
#### Line Chart Visualizer (`src/components/visualization/visualizers/line.visualizer.ts`)
198+
199+
- **Best for**: Displaying trends and changes over time
200+
- **Configuration**: Optimized for time-series data and continuous variables
201+
202+
#### Pie Chart Visualizer (`src/components/visualization/visualizers/pie.visualizer.ts`)
203+
204+
- **Best for**: Showing proportions and percentages of a whole
205+
- **Configuration**: Automatically identifies categorical data and corresponding values
206+
207+
### Usage
208+
209+
#### Basic Setup
210+
211+
```ts
212+
import {VisualizerComponent} from 'lb4-llm-chat-component';
213+
214+
export class MyApplication extends BootMixin(
215+
ServiceMixin(RepositoryMixin(RestApplication)),
216+
) {
217+
constructor(options: ApplicationConfig = {}) {
218+
// Add the visualizer component
219+
this.component(VisualizerComponent);
220+
221+
// ... other configuration
222+
}
223+
}
224+
```
225+
226+
#### Generate Visualization Tool
227+
228+
The component provides a `generate-visualization` tool that can be used by the LLM to create visualizations:
229+
230+
- **Input**: Takes a user prompt and dataset ID from a previously generated query
231+
- **Process**: Automatically selects the best visualization type and generates optimal configuration
232+
- **Output**: Renders the visualization in the UI for the user
233+
234+
#### Example Usage Flow
235+
236+
1. User asks: "Show me sales by region as a chart"
237+
2. LLM uses `generate-query` tool to create a dataset with sales data by region
238+
3. LLM uses `generate-visualization` tool with the dataset ID
239+
4. System selects bar chart as the most appropriate visualization
240+
5. Chart is rendered with regions on x-axis and sales values on y-axis
241+
242+
### Visualization Graph Flow
243+
244+
The visualization process follows a structured graph workflow (`src/components/visualization/visualization.graph.ts:9`):
245+
246+
1. **Get Dataset Data** - Retrieves the dataset and query information
247+
2. **Select Visualization** - Chooses the most appropriate chart type based on data structure
248+
3. **Render Visualization** - Generates the final chart configuration and displays it
249+
250+
### Creating Custom Visualizers
251+
252+
You can extend the system with custom visualizers by implementing the `IVisualizer` interface (`src/components/visualization/types.ts:4`):
253+
254+
```ts
255+
import {visualizer} from 'lb4-llm-chat-component';
256+
import {IVisualizer, VisualizationGraphState} from 'lb4-llm-chat-component';
257+
258+
@visualizer()
259+
export class CustomVisualizer implements IVisualizer {
260+
name = 'custom-chart';
261+
description = 'Description of when to use this visualizer';
262+
263+
async getConfig(state: VisualizationGraphState): Promise<AnyObject> {
264+
// Generate configuration based on the data and user prompt
265+
return {
266+
// your custom chart configuration
267+
};
268+
}
269+
}
270+
```
271+
272+
### Configuration
273+
274+
The visualizer component automatically registers all available visualizers and makes them available to the LLM. No additional configuration is required for basic usage. You can register a new visualizer using the `@visualizer` decorator on a class following the IVisualizer interface.
275+
276+
### Integration with DbQueryComponent
277+
278+
The visualizer component works seamlessly with the `DbQueryComponent`:
279+
280+
1. Use database query tools to generate datasets
281+
2. The visualization tool automatically accesses dataset metadata including:
282+
- SQL query structure
283+
- Query description
284+
- User's original prompt
285+
3. This context helps generate more accurate and relevant visualizations
286+
176287
## Providing Context
177288

178289
There are two ways to provide context to the LLM -

0 commit comments

Comments
 (0)