csv-charts-ai 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -20
- package/dist/charts.d.ts +41 -1
- package/dist/charts.js +199 -121
- package/dist/charts.js.map +1 -1
- package/dist/index.d.ts +91 -13
- package/dist/index.js +108 -64
- package/dist/index.js.map +1 -1
- package/package.json +15 -7
package/README.md
CHANGED
|
@@ -10,22 +10,36 @@ AI-powered CSV analysis, chart generation, and interactive visualization. Built
|
|
|
10
10
|
pnpm add csv-charts-ai
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Then install **only the AI provider(s) you need**:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Pick one or more
|
|
17
|
+
pnpm add @ai-sdk/openai # OpenAI / OpenAI-compatible (Ollama, vLLM, LM Studio…)
|
|
18
|
+
pnpm add @ai-sdk/anthropic # Anthropic
|
|
19
|
+
pnpm add @ai-sdk/google # Google Generative AI
|
|
20
|
+
pnpm add @ai-sdk/mistral # Mistral
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Core dependencies (`ai`, `zod`, `read-excel-file`) are bundled. AI provider SDKs are **optional peer dependencies** — you only install what you use.
|
|
14
24
|
|
|
15
25
|
**Optional peer dependencies** (only for React chart components): `react`, `recharts`, `lucide-react`.
|
|
16
26
|
|
|
17
27
|
## Quick Start
|
|
18
28
|
|
|
19
29
|
```ts
|
|
20
|
-
import { parseCSV, analyzeData, suggestQuestions } from "csv-charts-ai";
|
|
30
|
+
import { registerProvider, fromSDK, parseCSV, analyzeData, suggestQuestions } from "csv-charts-ai";
|
|
31
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
32
|
+
|
|
33
|
+
// 1. Register your provider(s) — once, at app startup
|
|
34
|
+
registerProvider("openai", fromSDK(createOpenAI));
|
|
21
35
|
|
|
22
|
-
//
|
|
36
|
+
// 2. Parse CSV string into structured data
|
|
23
37
|
const data = parseCSV(`name,age,city,salary
|
|
24
38
|
Alice,30,Paris,75000
|
|
25
39
|
Bob,25,London,62000
|
|
26
40
|
Charlie,35,Berlin,88000`);
|
|
27
41
|
|
|
28
|
-
//
|
|
42
|
+
// 3. Run full AI analysis (summary + anomalies + charts) in parallel
|
|
29
43
|
const result = await analyzeData({
|
|
30
44
|
model: { apiKey: "sk-...", model: "gpt-4o" },
|
|
31
45
|
data,
|
|
@@ -35,7 +49,7 @@ console.log(result.summary.keyInsights);
|
|
|
35
49
|
console.log(`Found ${result.anomalies.length} anomalies`);
|
|
36
50
|
console.log(`Generated ${result.charts.length} chart suggestions`);
|
|
37
51
|
|
|
38
|
-
//
|
|
52
|
+
// 4. Suggest questions the user could ask
|
|
39
53
|
const questions = await suggestQuestions({
|
|
40
54
|
model: { apiKey: "sk-...", model: "gpt-4o" },
|
|
41
55
|
data,
|
|
@@ -43,6 +57,56 @@ const questions = await suggestQuestions({
|
|
|
43
57
|
questions.forEach(q => console.log(`[${q.category}] ${q.question}`));
|
|
44
58
|
```
|
|
45
59
|
|
|
60
|
+
## Provider Setup
|
|
61
|
+
|
|
62
|
+
Register AI providers **once** at app startup, before calling any AI function. You only install and register the providers you need.
|
|
63
|
+
|
|
64
|
+
### Using `@ai-sdk/*` packages
|
|
65
|
+
|
|
66
|
+
The `fromSDK()` helper wraps any `@ai-sdk/*` creator into the format the library expects:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { registerProvider, fromSDK } from "csv-charts-ai";
|
|
70
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
71
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
72
|
+
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
73
|
+
import { createMistral } from "@ai-sdk/mistral";
|
|
74
|
+
|
|
75
|
+
registerProvider("openai", fromSDK(createOpenAI));
|
|
76
|
+
registerProvider("anthropic", fromSDK(createAnthropic));
|
|
77
|
+
registerProvider("google", fromSDK(createGoogleGenerativeAI));
|
|
78
|
+
registerProvider("mistral", fromSDK(createMistral));
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Custom / self-hosted providers
|
|
82
|
+
|
|
83
|
+
For full control, pass a `ProviderFactory` directly — a function that receives `{ apiKey, model, baseURL?, headers? }` and returns a `LanguageModel`:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { registerProvider } from "csv-charts-ai";
|
|
87
|
+
|
|
88
|
+
registerProvider("my-llm", (config) => {
|
|
89
|
+
return myCustomSDK.createModel(config.apiKey, config.model);
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Batch registration
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { registerProviders, fromSDK } from "csv-charts-ai";
|
|
97
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
98
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
99
|
+
|
|
100
|
+
registerProviders({
|
|
101
|
+
openai: fromSDK(createOpenAI),
|
|
102
|
+
anthropic: fromSDK(createAnthropic),
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Aliases
|
|
107
|
+
|
|
108
|
+
npm package names are resolved automatically — `"@ai-sdk/openai"` and `"openai"` map to the same slot. So `createModel({ provider: "openai" })` and `createAppModel({ providerNpm: "@ai-sdk/openai" })` both work after a single registration.
|
|
109
|
+
|
|
46
110
|
## CSV Parsing
|
|
47
111
|
|
|
48
112
|
Parse CSV strings into the `TabularData` format with automatic delimiter detection and column type inference.
|
|
@@ -105,13 +169,13 @@ All AI functions accept either a simple config object or a pre-built `LanguageMo
|
|
|
105
169
|
```ts
|
|
106
170
|
import { suggestCharts } from "csv-charts-ai";
|
|
107
171
|
|
|
108
|
-
// Simple — OpenAI
|
|
172
|
+
// Simple — OpenAI (provider must be registered, see Provider Setup)
|
|
109
173
|
const charts = await suggestCharts({
|
|
110
174
|
model: { apiKey: "sk-...", model: "gpt-4o" },
|
|
111
175
|
data,
|
|
112
176
|
});
|
|
113
177
|
|
|
114
|
-
// Custom endpoint — Ollama / vLLM / LM Studio
|
|
178
|
+
// Custom endpoint — Ollama / vLLM / LM Studio (uses the "openai" provider)
|
|
115
179
|
const charts = await suggestCharts({
|
|
116
180
|
model: { apiKey: "", model: "llama3", baseURL: "http://localhost:11434/v1" },
|
|
117
181
|
data,
|
|
@@ -123,8 +187,9 @@ const charts = await suggestCharts({
|
|
|
123
187
|
data,
|
|
124
188
|
});
|
|
125
189
|
|
|
126
|
-
// Advanced — any LanguageModel instance
|
|
127
|
-
import {
|
|
190
|
+
// Advanced — any LanguageModel instance (no registration needed)
|
|
191
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
192
|
+
const anthropic = createAnthropic({ apiKey: "sk-ant-..." });
|
|
128
193
|
const charts = await suggestCharts({
|
|
129
194
|
model: anthropic("claude-sonnet-4-20250514"),
|
|
130
195
|
data,
|
|
@@ -349,9 +414,12 @@ You can also pass `className` to any component to add classes alongside the buil
|
|
|
349
414
|
The core entry point (`csv-charts-ai`) works without React — use it in Node.js scripts, APIs, or CLI tools:
|
|
350
415
|
|
|
351
416
|
```ts
|
|
352
|
-
import { parseCSV, analyzeData } from "csv-charts-ai";
|
|
417
|
+
import { registerProvider, fromSDK, parseCSV, analyzeData } from "csv-charts-ai";
|
|
418
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
353
419
|
import { readFileSync } from "fs";
|
|
354
420
|
|
|
421
|
+
registerProvider("openai", fromSDK(createOpenAI));
|
|
422
|
+
|
|
355
423
|
const csv = readFileSync("sales.csv", "utf-8");
|
|
356
424
|
const data = parseCSV(csv);
|
|
357
425
|
|
|
@@ -387,6 +455,17 @@ console.log(result.summary.keyInsights);
|
|
|
387
455
|
| `suggestQuestions(options)` | Suggest interesting questions to ask about the data |
|
|
388
456
|
| `analyzeData(options)` | Full pipeline: summary + anomalies + charts in parallel |
|
|
389
457
|
|
|
458
|
+
## Provider Registry Reference
|
|
459
|
+
|
|
460
|
+
| Export | Description |
|
|
461
|
+
|--------|-------------|
|
|
462
|
+
| `registerProvider(name, factory)` | Register a provider by name |
|
|
463
|
+
| `registerProviders(map)` | Register multiple providers at once |
|
|
464
|
+
| `fromSDK(creator)` | Wrap an `@ai-sdk/*` creator into a `ProviderFactory` |
|
|
465
|
+
| `getProvider(name)` | Get a registered provider (or `undefined`) |
|
|
466
|
+
| `hasProvider(name)` | Check if a provider is registered |
|
|
467
|
+
| `clearProviders()` | Remove all registered providers (for testing) |
|
|
468
|
+
|
|
390
469
|
## Utilities Reference
|
|
391
470
|
|
|
392
471
|
| Export | Description |
|
|
@@ -443,16 +522,17 @@ Match modes: `"index"` (positional), `"key"` (by column value), `"content"` (ful
|
|
|
443
522
|
|
|
444
523
|
## Provider Support
|
|
445
524
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
| Provider | Config |
|
|
449
|
-
|
|
450
|
-
| OpenAI | `{ apiKey, model }` |
|
|
451
|
-
| Anthropic | `{ provider: "anthropic", apiKey, model }` |
|
|
452
|
-
| Google | `{ provider: "google", apiKey, model }` |
|
|
453
|
-
| Mistral | `{ provider: "mistral", apiKey, model }` |
|
|
454
|
-
| Ollama / vLLM / LM Studio | `{ apiKey: "", model, baseURL }` |
|
|
455
|
-
|
|
|
525
|
+
Install only the provider(s) you need and register them at startup (see [Provider Setup](#provider-setup)).
|
|
526
|
+
|
|
527
|
+
| Provider | Install | Config |
|
|
528
|
+
|----------|---------|--------|
|
|
529
|
+
| OpenAI | `@ai-sdk/openai` | `{ apiKey, model }` |
|
|
530
|
+
| Anthropic | `@ai-sdk/anthropic` | `{ provider: "anthropic", apiKey, model }` |
|
|
531
|
+
| Google | `@ai-sdk/google` | `{ provider: "google", apiKey, model }` |
|
|
532
|
+
| Mistral | `@ai-sdk/mistral` | `{ provider: "mistral", apiKey, model }` |
|
|
533
|
+
| Ollama / vLLM / LM Studio | `@ai-sdk/openai` | `{ apiKey: "", model, baseURL }` |
|
|
534
|
+
| Custom provider | — | `registerProvider("name", factory)` |
|
|
535
|
+
| Any LanguageModel | — | Pass instance directly |
|
|
456
536
|
|
|
457
537
|
## License
|
|
458
538
|
|
package/dist/charts.d.ts
CHANGED
|
@@ -66,4 +66,44 @@ declare function ChartThemeProvider({ theme, children, }: {
|
|
|
66
66
|
}): react_jsx_runtime.JSX.Element;
|
|
67
67
|
declare function useChartTheme(): ChartTheme;
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
/** Props accepted by every chart icon component. */
|
|
70
|
+
interface ChartIconProps {
|
|
71
|
+
className?: string;
|
|
72
|
+
}
|
|
73
|
+
/** A React component that renders an icon. */
|
|
74
|
+
type ChartIcon = React.ComponentType<ChartIconProps>;
|
|
75
|
+
/** The full set of icons used by chart components. */
|
|
76
|
+
interface ChartIconSet {
|
|
77
|
+
RefreshCw: ChartIcon;
|
|
78
|
+
Download: ChartIcon;
|
|
79
|
+
SortAsc: ChartIcon;
|
|
80
|
+
SortDesc: ChartIcon;
|
|
81
|
+
RotateCcw: ChartIcon;
|
|
82
|
+
TrendingUp: ChartIcon;
|
|
83
|
+
Filter: ChartIcon;
|
|
84
|
+
ImageIcon: ChartIcon;
|
|
85
|
+
}
|
|
86
|
+
declare const defaultIcons: ChartIconSet;
|
|
87
|
+
/**
|
|
88
|
+
* Provide a custom icon set to chart components.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```tsx
|
|
92
|
+
* import { ChartIconProvider } from "csv-charts-ai/charts";
|
|
93
|
+
* import { RefreshCw, Download, ... } from "lucide-react";
|
|
94
|
+
*
|
|
95
|
+
* const lucideIcons = { RefreshCw, Download, SortAsc, SortDesc, RotateCcw, TrendingUp, Filter, ImageIcon: Image };
|
|
96
|
+
*
|
|
97
|
+
* <ChartIconProvider icons={lucideIcons}>
|
|
98
|
+
* <ChartDisplay data={data} charts={charts} />
|
|
99
|
+
* </ChartIconProvider>
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function ChartIconProvider({ icons, children, }: {
|
|
103
|
+
icons: Partial<ChartIconSet>;
|
|
104
|
+
children: React.ReactNode;
|
|
105
|
+
}): react_jsx_runtime.JSX.Element;
|
|
106
|
+
/** Get the current icon set from context. */
|
|
107
|
+
declare function useChartIcons(): ChartIconSet;
|
|
108
|
+
|
|
109
|
+
export { ChartConfig, ChartDisplay, type ChartDisplayProps, type ChartIcon, type ChartIconProps, ChartIconProvider, type ChartIconSet, ChartTheme, ChartThemeProvider, ChartToolbar, ChartType, SingleChart, type SingleChartProps, SortOrder, TabularData, defaultIcons, useChartIcons, useChartTheme };
|