Skip to content

Commit 8392a2e

Browse files
committed
Additional cleanup for context items
Signed-off-by: worksofliam <[email protected]>
1 parent 788c819 commit 8392a2e

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

src/aiProviders/context.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { JobManager } from "../config";
44
import Schemas, { AllSQLTypes, SQLType } from "../database/schemas";
55
import Statement from "../database/statement";
66
import { DB2_SYSTEM_PROMPT } from "./prompts";
7+
import { Db2ContextItems } from "./prompt";
78

89
export function canTalkToDb() {
910
return JobManager.getSelection() !== undefined;
@@ -23,12 +24,6 @@ interface MarkdownRef {
2324
SCHMEA?: string;
2425
}
2526

26-
interface ContextDefinition {
27-
id: string;
28-
type: string;
29-
content: any;
30-
}
31-
3227
/**
3328
* Builds a semantic representation of a database schema by fetching all objects
3429
* associated with the schema, cleaning them, and filtering out unnecessary properties.
@@ -167,7 +162,7 @@ function splitUpUserInput(input: string): string[] {
167162
*
168163
* @param {string} input - A string that may contain table references.
169164
*/
170-
export async function getSqlContextItems(input: string): Promise<{items: ContextDefinition[], refs: ResolvedSqlObject[]}> {
165+
export async function getSqlContextItems(input: string): Promise<{items: Db2ContextItems[], refs: ResolvedSqlObject[]}> {
171166
// Parse all SCHEMA.TABLE references first
172167
const tokens = splitUpUserInput(input);
173168

@@ -209,8 +204,8 @@ export async function getSqlContextItems(input: string): Promise<{items: Context
209204
};
210205
}
211206

212-
export async function getContentItemsForRefs(allObjects: ResolvedSqlObject[]): Promise<ContextDefinition[]> {
213-
const items: (ContextDefinition|undefined)[] = await Promise.all(
207+
export async function getContentItemsForRefs(allObjects: ResolvedSqlObject[]): Promise<Db2ContextItems[]> {
208+
const items: (Db2ContextItems|undefined)[] = await Promise.all(
214209
allObjects.map(async (o) => {
215210
try {
216211
if (o.sqlType === `SCHEMA`) {
@@ -221,9 +216,9 @@ export async function getContentItemsForRefs(allObjects: ResolvedSqlObject[]): P
221216
const content = await Schemas.generateSQL(o.schema, o.name, o.sqlType);
222217

223218
return {
224-
id: o.name,
225-
type: o.sqlType,
226-
content: content,
219+
name: `${o.sqlType.toLowerCase()} definition for ${o.name}`,
220+
description: `${o.sqlType} definition`,
221+
content: content
227222
};
228223
}
229224

src/aiProviders/copilot/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function activateChat(context: vscode.ExtensionContext) {
7979
});
8080

8181
messages.push(...contextItems.context.map(c => {
82+
// Passing in the same breaks the request?
8283
return vscode.LanguageModelChatMessage.Assistant(c.content);
8384
}));
8485

src/aiProviders/prompt.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export interface Db2ContextItems {
1515
name: string;
1616
description: string;
1717
content: string;
18-
specific?: "copilot"|"continue";
1918
}
2019

2120
export interface BuildResult {
@@ -57,13 +56,7 @@ export async function getContextItems(input: string, options: PromptOptions = {}
5756
progress(`Finding objects to work with...`);
5857
const context = await getSqlContextItems(input);
5958

60-
for (const sqlObj of context.items) {
61-
contextItems.push({
62-
name: `${sqlObj.type.toLowerCase()} definition for ${sqlObj.id}`,
63-
content: sqlObj.content,
64-
description: `${sqlObj.type} definition`,
65-
});
66-
}
59+
contextItems.push(...context.items);
6760

6861
if (context.refs.filter(r => r.sqlType === `TABLE`).length >= 2) {
6962
const randomIndexA = Math.floor(Math.random() * context.refs.length);
@@ -85,20 +78,14 @@ export async function getContextItems(input: string, options: PromptOptions = {}
8578
const relatedObjects = await Schemas.getRelatedObjects(ref);
8679
const contentItems = await getContentItemsForRefs(relatedObjects);
8780

81+
contextItems.push(...contentItems);
82+
8883
if (relatedObjects.length === 1) {
8984
followUps.push(`How is ${prettyNameRef} related to ${Statement.prettyName(relatedObjects[0].name)}?`);
9085
} else if (ref.sqlType === `TABLE`) {
9186
followUps.push(`What are some objects related to that table?`);
9287
}
9388

94-
for (const sqlObj of contentItems) {
95-
contextItems.push({
96-
name: `${sqlObj.type.toLowerCase()} definition for ${sqlObj.id}`,
97-
content: sqlObj.content,
98-
description: `${sqlObj.type} definition`,
99-
});
100-
}
101-
10289
} else if (context.refs.length > 1) {
10390
const randomRef = context.refs[Math.floor(Math.random() * context.refs.length)];
10491
const prettyNameRef = Statement.prettyName(randomRef.name);

0 commit comments

Comments
 (0)