Skip to content

Commit 5e2e05b

Browse files
committed
filter tables refs if already in context
1 parent dd257c2 commit 5e2e05b

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

src/aiProviders/continue/continueContextProvider.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
IContextProvider,
1212
LoadSubmenuItemsArgs,
1313
} from "../../..";
14-
15-
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.`
14+
import { DB2_SELF_PROMPT, DB2_SYSTEM_PROMPT } from "./prompts";
1615

1716
const db2ContextProviderDesc: ContextProviderDescription = {
1817
title: "db2i",
@@ -101,19 +100,22 @@ export class db2ContextProvider implements IContextProvider {
101100
const schema = this.getDefaultSchema();
102101
const fullInput = extras.fullInput;
103102
const contextItems: ContextItem[] = [];
103+
contextItems.push({
104+
name: `SYSTEM PROMPT`,
105+
description: `system prompt context`,
106+
content: DB2_SYSTEM_PROMPT,
107+
});
104108
try {
105109
switch (true) {
106-
case (fullInput.includes(`*SELF`) || query?.includes(`*SELF`)):
110+
case fullInput.includes(`*SELF`) || query?.includes(`*SELF`):
107111
// get current self code errors in job
108112
// build promt with error information
109113
// add to contextItems
110114

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

114-
let prompt = `Db2 for i self code errors\n`;
115-
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`;
116-
prompt += `Errors:\n`;
118+
let prompt = DB2_SELF_PROMPT.join(" ");
117119
prompt += JSON.stringify(selfCodes, null, 2);
118120

119121
contextItems.push({
@@ -131,24 +133,18 @@ export class db2ContextProvider implements IContextProvider {
131133
schema,
132134
fullInput.split(` `)
133135
);
134-
contextItems.push({
135-
name: `SYSTEM PROMPT`,
136-
description: `system prompt context`,
137-
content: DB2_SYSTEM_PROMPT,
138-
});
139136
for (const table of Object.keys(tableRefs)) {
140137
const columnData: TableColumn[] = tableRefs[table];
141138
const tableSchema =
142139
columnData.length > 0 ? columnData[0].TABLE_SCHEMA : null;
143140

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

149145
contextItems.push({
150146
name: `${job.name}-${tableSchema}-${table}`,
151-
description: `Schema and table information or ${table}`,
147+
description: `Schema and table information for ${table}`,
152148
content: prompt,
153149
});
154150
}

src/aiProviders/continue/prompts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
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.`;
2+
3+
export const DB2_SELF_PROMPT = [`Db2 for i self code errors\n`,
4+
`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`,
5+
`Errors:\n`];

src/chat/context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ export async function findPossibleTables(stream: vscode.ChatResponseStream, sche
112112
const result: TableColumn[] = await JobManager.runSQL(objectFindStatement);
113113

114114
result.forEach(row => {
115-
if (!tables[row.TABLE_NAME]) tables[row.TABLE_NAME] = [];
116-
tables[row.TABLE_NAME].push(row);
115+
const tableName = row.TABLE_NAME.toLowerCase();
116+
if (!tables[tableName]) tables[tableName] = [];
117+
tables[tableName].push(row);
117118
});
118119
return tables;
119120
}

0 commit comments

Comments
 (0)