Skip to content

Commit e87cf27

Browse files
committed
Copilot cleanup
Signed-off-by: worksofliam <[email protected]>
1 parent 8f4fe49 commit e87cf27

File tree

7 files changed

+31
-227
lines changed

7 files changed

+31
-227
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Db2 for IBM i tools in VS Code",
55
"version": "1.6.0",
66
"engines": {
7-
"vscode": "^1.90.0"
7+
"vscode": "^1.95.0"
88
},
99
"icon": "media/logo.png",
1010
"keywords": [
@@ -128,26 +128,11 @@
128128
"id": "vscode-db2i.ai",
129129
"title": "Db2 for IBM i with AI",
130130
"properties": {
131-
"vscode-db2i.ai.provider": {
132-
"order": 0,
133-
"type": "string",
134-
"description": "Model Provider",
135-
"default": "none",
136-
"enum": [
137-
"none",
138-
"Ollama",
139-
"GitHub Copilot"
140-
],
141-
"enumDescriptions": [
142-
"Ollama instance, with specific model",
143-
"GitHub Copilot. Requires the GitHub Copilot extension to be installed"
144-
]
145-
},
146-
"vscode-db2i.ai.model": {
131+
"vscode-db2i.ai.copilotModel": {
147132
"order": 1,
148133
"type": "string",
149134
"description": "Model to use with the provider",
150-
"default": "ibm-granite"
135+
"default": "gpt-4o"
151136
}
152137
}
153138
},
@@ -329,11 +314,6 @@
329314
]
330315
},
331316
"commands": [
332-
{
333-
"command": "vscode-db2i.ai.changeModel",
334-
"title": "Change AI Model",
335-
"category": "Db2 for i"
336-
},
337317
{
338318
"command": "vscode-db2i.notebook.open",
339319
"title": "New Notebook",
@@ -1323,7 +1303,7 @@
13231303
"@halcyontech/vscode-ibmi-types": "^2.0.0",
13241304
"@types/glob": "^7.1.3",
13251305
"@types/node": "14.x",
1326-
"@types/vscode": "^1.90.0",
1306+
"@types/vscode": "^1.95.0",
13271307
"esbuild-loader": "^3.0.1",
13281308
"eslint": "^7.32.0",
13291309
"glob": "^7.1.7",

src/aiProviders/aiConfig.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/aiProviders/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function canTalkToDb() {
66
return JobManager.getSelection() !== undefined;
77
}
88

9-
export function getDefaultSchema(): string {
9+
export function getCurrentSchema(): string {
1010
const currentJob = JobManager.getSelection();
1111
return currentJob && currentJob.job.options.libraries[0]
1212
? currentJob.job.options.libraries[0]
Lines changed: 20 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
import ollama, { ListResponse } from "ollama";
22
import * as vscode from "vscode";
33
import Statement from "../../database/statement";
4-
import { AiConfig, AiProvider } from "../aiConfig";
54
import {
65
canTalkToDb,
76
findPossibleTables,
8-
getDefaultSchema,
7+
getCurrentSchema,
98
getSystemStatus,
10-
refsToMarkdown,
119
} from "../context";
12-
import { chatRequest } from "./send";
1310
import { JobManager } from "../../config";
1411

1512
const CHAT_ID = `vscode-db2i.chat`;
16-
let usingSchema = getDefaultSchema();
1713

1814
interface IDB2ChatResult extends vscode.ChatResult {
1915
metadata: {
2016
command: string;
2117
};
2218
}
2319

24-
interface ModelQuickPickItem extends vscode.QuickPickItem {
25-
provider: AiProvider;
26-
family: string;
27-
}
28-
2920
export function activateChat(context: vscode.ExtensionContext) {
3021
// chatHandler deals with the input from the chat windows,
3122
// and uses streamModelResponse to send the response back to the chat window
@@ -35,9 +26,11 @@ export function activateChat(context: vscode.ExtensionContext) {
3526
stream: vscode.ChatResponseStream,
3627
token: vscode.CancellationToken
3728
): Promise<IDB2ChatResult> => {
29+
const copilotFamily = request.model.family;
3830
let messages: vscode.LanguageModelChatMessage[];
3931

4032
if (canTalkToDb()) {
33+
let usingSchema = getCurrentSchema();
4134

4235
switch (request.command) {
4336
case `activity`:
@@ -56,7 +49,7 @@ export function activateChat(context: vscode.ExtensionContext) {
5649
vscode.LanguageModelChatMessage.User(request.prompt),
5750
];
5851

59-
await streamModelResponse(messages, stream, token);
52+
await copilotRequest(copilotFamily, messages, {}, token, stream);
6053

6154
return { metadata: { command: "activity" } };
6255

@@ -125,7 +118,7 @@ export function activateChat(context: vscode.ExtensionContext) {
125118

126119
messages.push(vscode.LanguageModelChatMessage.User(request.prompt))
127120

128-
await streamModelResponse(messages, stream, token);
121+
await copilotRequest(request.model.family, messages, {}, token, stream);
129122

130123
return { metadata: { command: "build" } };
131124
}
@@ -139,98 +132,23 @@ export function activateChat(context: vscode.ExtensionContext) {
139132
const chat = vscode.chat.createChatParticipant(CHAT_ID, chatHandler);
140133
chat.iconPath = new vscode.ThemeIcon(`database`);
141134

142-
const changeModelCommand = vscode.commands.registerCommand(
143-
`vscode-db2i.ai.changeModel`,
144-
selectProviderAndModel
145-
);
146-
147-
context.subscriptions.push(chat, changeModelCommand);
148-
}
149-
150-
let lastSelectedModel: string | null = null;
151-
152-
async function showModelProviderIfNeeded(
153-
stream: vscode.ChatResponseStream,
154-
chosenProvider: AiProvider,
155-
chosenModel: string
156-
) {
157-
const currentModel = AiConfig.getModel();
158-
159-
if (lastSelectedModel === null || lastSelectedModel !== currentModel) {
160-
stream.markdown(
161-
`**Provider👨‍💻:** ${chosenProvider}\n\n**Model🧠:** ${chosenModel}\n\n***\n\n`
162-
);
163-
lastSelectedModel = currentModel;
164-
}
135+
context.subscriptions.push(chat);
165136
}
166137

167-
async function streamModelResponse(
138+
async function copilotRequest(
139+
model: string,
168140
messages: vscode.LanguageModelChatMessage[],
169-
stream: vscode.ChatResponseStream,
170-
token: vscode.CancellationToken
171-
) {
172-
const chosenProvider = AiConfig.getProvider();
173-
const chosenModel = AiConfig.getModel();
174-
175-
if (chosenProvider === `none`) {
176-
stream.markdown(
177-
`No AI provider selected. Please select an AI provider and model.`
178-
);
179-
stream.button({
180-
command: `vscode-db2i.ai.changeModel`,
181-
title: `Select AI Provider and Model`,
182-
});
183-
return;
184-
}
185-
186-
showModelProviderIfNeeded(stream, chosenProvider, chosenModel);
187-
stream.progress(`Provider: ${chosenProvider} Model: ${chosenModel}`);
188-
189-
return chatRequest(chosenProvider, messages, {}, token, stream);
190-
}
191-
192-
async function selectProviderAndModel() {
193-
const selected = AiConfig.getModel();
194-
const copilotModels = await vscode.lm.selectChatModels();
195-
let ollamaModels: ListResponse = { models: [] };
196-
197-
// try {
198-
// ollamaModels = await ollama.list();
199-
// } catch (e) {}
200-
201-
const provider = await vscode.window.showQuickPick(
202-
[
203-
{ kind: vscode.QuickPickItemKind.Separator, label: "Ollama Models" },
204-
...ollamaModels.models.map(
205-
(model): ModelQuickPickItem => ({
206-
label: model.name,
207-
family: model.name,
208-
provider: "Ollama",
209-
iconPath: new vscode.ThemeIcon("heart"),
210-
description: selected === model.name ? "Selected" : "",
211-
})
212-
),
213-
{
214-
kind: vscode.QuickPickItemKind.Separator,
215-
label: "GitHub Copilot Models",
216-
},
217-
...copilotModels.map(
218-
(model): ModelQuickPickItem => ({
219-
label: model.name,
220-
family: model.family,
221-
provider: "GitHub Copilot",
222-
iconPath: new vscode.ThemeIcon("copilot"),
223-
description: selected === model.family ? "Selected" : "",
224-
})
225-
),
226-
],
227-
{
228-
title: "Select the AI model",
141+
options: vscode.LanguageModelChatRequestOptions,
142+
token: vscode.CancellationToken,
143+
stream: vscode.ChatResponseStream
144+
): Promise<void> {
145+
const models = await vscode.lm.selectChatModels({ family: model });
146+
if (models.length > 0) {
147+
const [first] = models;
148+
const response = await first.sendRequest(messages, options, token);
149+
150+
for await (const fragment of response.text) {
151+
stream.markdown(fragment);
229152
}
230-
);
231-
232-
if (provider && "provider" in provider && "family" in provider) {
233-
AiConfig.setProvider(provider.provider);
234-
AiConfig.setModel(provider.family);
235153
}
236-
}
154+
}

src/aiProviders/copilot/send.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { JobManagerView } from "./views/jobManager/jobManagerView";
2323
import { SelfTreeDecorationProvider, selfCodesResultsView } from "./views/jobManager/selfCodes/selfCodesResultsView";
2424
import { registerContinueProvider } from "./aiProviders/continue/continueContextProvider";
2525
import { queryHistory } from "./views/queryHistoryView";
26-
import { activateChat } from "./aiProviders/copilot/chat";
26+
import { activateChat } from "./aiProviders/copilot";
2727

2828
export interface Db2i {
2929
sqlJobManager: SQLJobManager,

0 commit comments

Comments
 (0)