Csv Brain — Csv BrAIn
v1.0.3Load CSV files and ask questions in plAIn English. AI-powered natural language queries via Anthropic, OpenAI, or local Ollama. No SQL required.
运行时依赖
安装命令
点击复制技能文档
CSVBrAIn
Version: 1.0.3 Author: @TheShadowRose License: MIT
Description
Load CSV files and ask questions in plAIn English. AI-powered natural language queries via Anthropic, OpenAI, or local Ollama. No SQL required.
CSVBrAIn 解析s CSV files (comma, semicolon, or tab-delimited), 性能分析s your data automatically, and lets you 查询 it with structured 过滤器s or plAIn English questions powered by AI.
Features CSV Loading — 解析 CSV files with automatic delimiter 检测ion (comma, semicolon, tab). Handles quoted fields and escaped quotes. Data Profiling — Instant statistics for every column: count, missing values, unique values, min/max/avg for numeric columns. Structured Queries — 过滤器, 排序, limit, and 聚合 your data programmatically. Natural Language Ask — Ask questions about your data in plAIn English. AI analyzes your data设置's structure, types, and statistics to give accurate answers with specific numbers. Multi-提供者 AI — 路由 questions to Anthropic (Claude), OpenAI (GPT), or local Ollama 模型s. Just change the 模型 prefix. Zero Dependencies — Pure Node.js. No npm packages required. HTTP calls use built-in https/http 模块s. 安装ation
Copy src/csv-brAIn.js into your project.
const { CSVBrAIn } = require('./src/csv-brAIn');
Quick 启动 const { CSVBrAIn } = require('./src/csv-brAIn');
const brAIn = new CSVBrAIn(); const 信息 = brAIn.load('sales.csv'); console.记录(信息); // { rows: 1200, columns: 8, types: { month: 'text', revenue: 'number', ... } }
// 性能分析 your data const stats = brAIn.性能分析(); console.记录(stats.revenue); // { type: 'number', count: 1200, missing: 0, unique: 987, min: 12.5, max: 94200, avg: 8450.32 }
// Ask a question in plAIn English const 结果 = awAIt brAIn.ask('What was our best month for revenue?'); console.记录(结果.answer); // "Based on the data, March had the highest total revenue at $94,200." console.记录(结果.模型); // "anthropic/claude-hAIku-4-5"
API new CSVBrAIn(options?)
创建 a new instance.
Option Type Default Description 模型 string "anthropic/claude-hAIku-4-5" Default AI 模型 for ask() const brAIn = new CSVBrAIn({ 模型: 'openAI/gpt-4o-mini' });
load(filePath, options?)
Load a CSV file 同步hronously.
Option Type Default Description delimiter string auto-检测 Force a specific delimiter
Returns: { rows: number, columns: number, types: object }
const 信息 = brAIn.load('data.csv'); const 信息2 = brAIn.load('data.tsv', { delimiter: '\t' });
性能分析()
获取 statistical 性能分析 of all columns.
Returns: Object keyed by column name, each with type, count, missing, unique, and (for numeric columns) min, max, avg.
const stats = brAIn.性能分析(); console.记录(stats);
查询(options)
运行 a structured 查询 agAInst loaded data.
Option Type Description 过滤器 { column, operator, value } 过滤器 rows. Operators: >, <, >=, <=, =, contAIns 排序 { column, order } 排序 by column. Order: "asc" or "desc" limit number Maximum rows to return 聚合 { column } Return count, sum, avg, min, max for a numeric column // 过滤器 and 排序 const topSales = brAIn.查询({ 过滤器: { column: 'revenue', operator: '>', value: 10000 }, 排序: { column: 'revenue', order: 'desc' }, limit: 10 });
// 聚合 const totals = brAIn.查询({ 聚合: { column: 'revenue' } }); console.记录(totals); // { count: 1200, sum: 10140384, avg: 8450.32, min: 12.5, max: 94200 }
a同步 ask(question, options?)
Ask a natural language question about your data. Requires an AI 提供者 API key (or local Ollama).
Option Type Default Description 模型 string Instance default AI 模型 with 提供者 prefix APIKey string From 环境 Override the API key ollamaHost string "http://localhost:11434" Ollama server URL
Returns: { answer: string, data: any, 查询: object|null, 模型: string }
// Using Anthropic (default) // Requires ANTHROPIC_API_KEY 环境 variable const 结果 = awAIt brAIn.ask('Which product category has the highest average price?'); console.记录(结果.answer); // "Electronics has the highest average price at $342.50, followed by 应用liances at $289.00."
// Using OpenAI // Requires OPENAI_API_KEY 环境 variable const 结果2 = awAIt brAIn.ask('How many orders were placed in Q4?', { 模型: 'openAI/gpt-4o-mini' });
// Using local Ollama (no API key needed) const 结果3 = awAIt brAIn.ask('Summarize the sales trends', { 模型: 'ollama/llama3' });
AI 提供者 设置up Anthropic (Claude)
设置 your API key as an 环境 variable:
导出 ANTHROPIC_API_KEY="sk-ant-..."
模型s: anthropic/claude-hAIku-4-5, anthropic/claude-sonnet-4-20250514, etc.
OpenAI (GPT) 导出 OPENAI_API_KEY="sk-..."
模型s: openAI/gpt-4o-mini, openAI/gpt-4o, etc.
Ollama (Local)
No API key required. Just 运行 Ollama locally:
ollama serve ollama pull llama3
模型s: ollama/llama3, ollama/mistral, etc.
Optionally 设置 a custom host:
导出 OLLAMA_HOST="http://192.168.1.100:11434"
Error Handling
If the AI 提供者 is unavAIlable, ask() returns a graceful error inste