MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / createSQLPrompt

Function createSQLPrompt

frontend/src/lib/ai/prompts/sqlPrompts.ts:368–409  ·  view source on GitHub ↗
(
  userPrompt: string,
  context: AIContextData,
  options?: {
    includeExplanation?: boolean;
    maxRows?: number;
    includeOptimization?: boolean;
  }
)

Source from the content-addressed store, hash-verified

366};
367
368export const createSQLPrompt = (
369 userPrompt: string,
370 context: AIContextData,
371 options?: {
372 includeExplanation?: boolean;
373 maxRows?: number;
374 includeOptimization?: boolean;
375 }
376): string => {
377 const maxRows = options?.maxRows || 100;
378 let prompt = `Generate a SQL query for: "${userPrompt}"
379
380Table: ${context.tableName}
381Available columns: ${context.schema
382 .map((col) => `${col.name} (${col.type})`)
383 .join(', ')}
384
385Requirements:
386- Use DuckDB syntax
387- Include LIMIT ${maxRows} unless the user specifically requests more
388- Ensure column names match exactly
389- Handle data types properly`;
390
391 if (options?.includeExplanation) {
392 prompt += '\n- Include a brief explanation of the query';
393 }
394
395 if (options?.includeOptimization) {
396 prompt += '\n- Suggest any performance optimizations';
397 }
398
399 if (context.sampleData && context.sampleData.length > 0) {
400 const sampleDataStr = context.sampleData
401 .slice(0, 3)
402 .map((row) => JSON.stringify(row))
403 .join('\n');
404 prompt += `\n\nSample data for reference:
405${sampleDataStr}`;
406 }
407
408 return prompt;
409};
410
411export const createDataAnalysisPrompt = (
412 userPrompt: string,

Callers 6

generateSQLMethod · 0.90
generateSQLMethod · 0.90
generateSQLMethod · 0.90
generateSQLMethod · 0.90
generateSQLMethod · 0.90
generateSQLMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected