Skip to content

Commit

Permalink
filter tables refs if already in context
Browse files Browse the repository at this point in the history
  • Loading branch information
ajshedivy committed Oct 29, 2024
1 parent dd257c2 commit 5e2e05b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
24 changes: 10 additions & 14 deletions src/aiProviders/continue/continueContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
IContextProvider,
LoadSubmenuItemsArgs,
} from "../../..";

const DB2_SYSTEM_PROMPT = `You are an expert in IBM i, specializing in database features of Db2 for i. Your role is to assist developers in writing and debugging their SQL queries, as well as providing SQL programming advice and best practices.`
import { DB2_SELF_PROMPT, DB2_SYSTEM_PROMPT } from "./prompts";

const db2ContextProviderDesc: ContextProviderDescription = {
title: "db2i",
Expand Down Expand Up @@ -101,19 +100,22 @@ export class db2ContextProvider implements IContextProvider {
const schema = this.getDefaultSchema();
const fullInput = extras.fullInput;
const contextItems: ContextItem[] = [];
contextItems.push({
name: `SYSTEM PROMPT`,
description: `system prompt context`,
content: DB2_SYSTEM_PROMPT,
});
try {
switch (true) {
case (fullInput.includes(`*SELF`) || query?.includes(`*SELF`)):
case fullInput.includes(`*SELF`) || query?.includes(`*SELF`):
// get current self code errors in job
// build promt with error information
// add to contextItems

if (job) {
const selfCodes = await this.getSelfCodes(job);

let prompt = `Db2 for i self code errors\n`;
prompt += `Summarize the SELF code errors provided. The SQL Error Logging Facility (SELF) provides a mechanism that can be used to understand when SQL statements are encountering specific SQL errors or warnings. SELF is built into Db2 for i and can be enabled in specific jobs or system wide. Provide additional details about the errors and how to fix them.\n`;
prompt += `Errors:\n`;
let prompt = DB2_SELF_PROMPT.join(" ");
prompt += JSON.stringify(selfCodes, null, 2);

contextItems.push({
Expand All @@ -131,24 +133,18 @@ export class db2ContextProvider implements IContextProvider {
schema,
fullInput.split(` `)
);
contextItems.push({
name: `SYSTEM PROMPT`,
description: `system prompt context`,
content: DB2_SYSTEM_PROMPT,
});
for (const table of Object.keys(tableRefs)) {
const columnData: TableColumn[] = tableRefs[table];
const tableSchema =
columnData.length > 0 ? columnData[0].TABLE_SCHEMA : null;

// create context item
let prompt = `Db2 for i schema ${tableSchema} table ${table}\n`;
prompt += `SYSTEM Prompt`
let prompt = `Db2 for i Table meta data for schema ${tableSchema} table ${table}\n`;
prompt += `Column Info: ${JSON.stringify(columnData)}\n\n`;

contextItems.push({
name: `${job.name}-${tableSchema}-${table}`,
description: `Schema and table information or ${table}`,
description: `Schema and table information for ${table}`,
content: prompt,
});
}
Expand Down
5 changes: 5 additions & 0 deletions src/aiProviders/continue/prompts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const DB2_SYSTEM_PROMPT = `You are an expert in IBM i, specializing in database features of Db2 for i. Your role is to assist developers in writing and debugging their SQL queries, as well as providing SQL programming advice and best practices.`;

export const DB2_SELF_PROMPT = [`Db2 for i self code errors\n`,
`Summarize the SELF code errors provided. The SQL Error Logging Facility (SELF) provides a mechanism that can be used to understand when SQL statements are encountering specific SQL errors or warnings. SELF is built into Db2 for i and can be enabled in specific jobs or system wide. Provide additional details about the errors and how to fix them.\n`,
`Errors:\n`];
5 changes: 3 additions & 2 deletions src/chat/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ export async function findPossibleTables(stream: vscode.ChatResponseStream, sche
const result: TableColumn[] = await JobManager.runSQL(objectFindStatement);

result.forEach(row => {
if (!tables[row.TABLE_NAME]) tables[row.TABLE_NAME] = [];
tables[row.TABLE_NAME].push(row);
const tableName = row.TABLE_NAME.toLowerCase();
if (!tables[tableName]) tables[tableName] = [];
tables[tableName].push(row);
});
return tables;
}
Expand Down

0 comments on commit 5e2e05b

Please sign in to comment.