Skip to content

Commit

Permalink
feat(backend): improve analyze of CSV files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Feb 23, 2025
1 parent d6527c4 commit 62901cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ export class CsvAIEmbeddingGenerator implements AIEmbeddingGenerator {

generate = (attrs: Omit<AIEmbeddingGenerateAttrs, 'chunkFn'>) => this.textEmbeddingGenerator.generate({
...attrs,
chunkFn: text => pipe(
text.split('\n'),
A.chunksOf(40),
A.map(chunk => chunk.join('\n')),
),
chunkFn: (text) => {
const lines = text.split('\n');
const header = lines[0];
const dataLines = lines.slice(1);

return pipe(
dataLines,
A.chunksOf(40),
A.map(chunk => [header, ...chunk].join('\n')),
);
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { featureXML } from './feature-xml-tag';
export function createHtmlPreviewContextPrompt(): string {
return featureXML({
name: 'HTML Preview',
description: 'You can embed HTML content with interactive data visualizations, statistical analysis, and charts using markdown HTML tags. When presenting data analysis results, prefer visual representations using appropriate chart types. If the user provides data files, analyze their content to create relevant visualizations.',
description: 'You can embed HTML content with interactive data visualizations, statistical analysis, and charts using markdown HTML tags. All charts and visualizations MUST be generated using real data from provided files - never use example or dummy data.',
children: [
xml('rules', {
children: [
Expand All @@ -20,6 +20,18 @@ export function createHtmlPreviewContextPrompt(): string {
attributes: { critical: 'true' },
children: ['CRITICAL: Maximum chart height must not exceed 450px'],
}),
xml('rule', {
attributes: { critical: 'true' },
children: ['CRITICAL: NEVER generate charts with example/dummy data - only use actual data from provided files'],
}),
xml('rule', {
attributes: { critical: 'true' },
children: ['CRITICAL: If no data files are provided, ask the user to provide the data instead of creating example visualizations'],
}),
xml('rule', {
attributes: { critical: 'true' },
children: ['CRITICAL: Always parse and validate data files before creating visualizations'],
}),
xml('rule', { children: ['Avoid calling getContext() on non-canvas elements'] }),
xml('rule', { children: ['Place charts and visualizations before their descriptive text'] }),
xml('rule', { children: ['All HTML must be self-contained with no local file dependencies'] }),
Expand All @@ -45,6 +57,8 @@ export function createHtmlPreviewContextPrompt(): string {
}),
xml('rule', { children: ['Extract meaningful patterns and relationships from provided data files'] }),
xml('rule', { children: ['Choose appropriate chart types based on the data structure and patterns'] }),
xml('rule', { children: ['Analyze the full dataset to determine appropriate chart scales and ranges'] }),
xml('rule', { children: ['Include data source attribution in chart descriptions'] }),
xml('chart-choice', {
attributes: { type: 'vector' },
children: [
Expand Down Expand Up @@ -195,6 +209,14 @@ export function createHtmlPreviewContextPrompt(): string {
\`\`\``,
],
}),
xml('example', {
attributes: {
description: 'Example of requesting data when none provided',
},
children: [
`Please provide the data file you'd like to visualize. I can help you create an appropriate chart based on your actual data.`,
],
}),
],
}),
],
Expand Down

0 comments on commit 62901cc

Please sign in to comment.