(
userPrompt: string,
context: AIContextData,
options?: {
includeExplanation?: boolean;
maxRows?: number;
includeOptimization?: boolean;
}
)
| 366 | }; |
| 367 | |
| 368 | export 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 | |
| 380 | Table: ${context.tableName} |
| 381 | Available columns: ${context.schema |
| 382 | .map((col) => `${col.name} (${col.type})`) |
| 383 | .join(', ')} |
| 384 | |
| 385 | Requirements: |
| 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 | |
| 411 | export const createDataAnalysisPrompt = ( |
| 412 | userPrompt: string, |
no outgoing calls
no test coverage detected