Skip to content

Commit 57aa120

Browse files
committed
show seletected on copilot models
1 parent ac41081 commit 57aa120

File tree

2 files changed

+46
-32
lines changed

2 files changed

+46
-32
lines changed

src/chat/chat.ts

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import ollama, { ListResponse } from "ollama";
12
import * as vscode from "vscode";
2-
import { JobManager } from "../config";
33
import Statement from "../database/statement";
4-
import { chatRequest } from "./send";
5-
import Configuration from "../configuration";
6-
import { getDefaultSchema, findPossibleTables, refsToMarkdown, getSystemStatus, canTalkToDb } from "./context";
74
import { AiConfig, AiProvider } from "./aiConfig";
8-
import ollama, { ListResponse } from "ollama";
5+
import {
6+
canTalkToDb,
7+
findPossibleTables,
8+
getDefaultSchema,
9+
getSystemStatus,
10+
refsToMarkdown,
11+
} from "./context";
12+
import { chatRequest } from "./send";
913

1014
const CHAT_ID = `vscode-db2i.chat`;
1115

@@ -32,7 +36,6 @@ export function activateChat(context: vscode.ExtensionContext) {
3236
let messages: vscode.LanguageModelChatMessage[];
3337

3438
if (canTalkToDb()) {
35-
3639
const usingSchema = getDefaultSchema();
3740

3841
switch (request.command) {
@@ -107,19 +110,21 @@ export function activateChat(context: vscode.ExtensionContext) {
107110
return { metadata: { command: "build" } };
108111
}
109112
} else {
110-
throw new Error(`Not connected to the database. Please check your configuration.`)
113+
throw new Error(
114+
`Not connected to the database. Please check your configuration.`
115+
);
111116
}
112117
};
113118

114119
const chat = vscode.chat.createChatParticipant(CHAT_ID, chatHandler);
115120
chat.iconPath = new vscode.ThemeIcon(`database`);
116121

117-
const changeModelCommand = vscode.commands.registerCommand(`vscode-db2i.ai.changeModel`, selectProviderAndModel);
118-
119-
context.subscriptions.push(
120-
chat,
121-
changeModelCommand
122+
const changeModelCommand = vscode.commands.registerCommand(
123+
`vscode-db2i.ai.changeModel`,
124+
selectProviderAndModel
122125
);
126+
127+
context.subscriptions.push(chat, changeModelCommand);
123128
}
124129

125130
async function streamModelResponse(
@@ -128,17 +133,20 @@ async function streamModelResponse(
128133
token: vscode.CancellationToken
129134
) {
130135
const chosenProvider = AiConfig.getProvider();
136+
const chosenModel = AiConfig.getModel();
131137

132138
if (chosenProvider === `none`) {
133-
stream.markdown(`No AI provider selected. Please select an AI provider and model.`);
139+
stream.markdown(
140+
`No AI provider selected. Please select an AI provider and model.`
141+
);
134142
stream.button({
135143
command: `vscode-db2i.ai.changeModel`,
136144
title: `Select AI Provider and Model`,
137145
});
138146
return;
139147
}
140148

141-
stream.progress(`Using ${chosenProvider}...`);
149+
stream.progress(`Provider: ${chosenProvider} Model: ${chosenModel}`);
142150

143151
return chatRequest(chosenProvider, messages, {}, token, stream);
144152
}
@@ -150,33 +158,40 @@ async function selectProviderAndModel() {
150158

151159
try {
152160
ollamaModels = await ollama.list();
153-
} catch (e) { }
161+
} catch (e) {}
154162

155163
const provider = await vscode.window.showQuickPick(
156164
[
157165
{ kind: vscode.QuickPickItemKind.Separator, label: "Ollama Models" },
158-
...ollamaModels.models.map((model): ModelQuickPickItem => ({
159-
label: model.name,
160-
family: model.name,
161-
provider: "Ollama",
162-
iconPath: new vscode.ThemeIcon("heart"),
163-
description: selected === model.name ? "Selected" : ""
164-
})),
165-
{ kind: vscode.QuickPickItemKind.Separator, label: "GitHub Copilot Models" },
166-
...copilotModels.map((model): ModelQuickPickItem => ({
167-
label: model.name,
168-
family: model.family,
169-
provider: "GitHub Copilot",
170-
iconPath: new vscode.ThemeIcon("copilot"),
171-
description: selected === model.name ? "Selected" : ""
172-
})),
166+
...ollamaModels.models.map(
167+
(model): ModelQuickPickItem => ({
168+
label: model.name,
169+
family: model.name,
170+
provider: "Ollama",
171+
iconPath: new vscode.ThemeIcon("heart"),
172+
description: selected === model.name ? "Selected" : "",
173+
})
174+
),
175+
{
176+
kind: vscode.QuickPickItemKind.Separator,
177+
label: "GitHub Copilot Models",
178+
},
179+
...copilotModels.map(
180+
(model): ModelQuickPickItem => ({
181+
label: model.name,
182+
family: model.family,
183+
provider: "GitHub Copilot",
184+
iconPath: new vscode.ThemeIcon("copilot"),
185+
description: selected === model.family ? "Selected" : "",
186+
})
187+
),
173188
],
174189
{
175190
title: "Select the AI model",
176191
}
177192
);
178193

179-
if (provider && 'provider' in provider && 'family' in provider) {
194+
if (provider && "provider" in provider && "family" in provider) {
180195
AiConfig.setProvider(provider.provider);
181196
AiConfig.setModel(provider.family);
182197
}

src/chat/send.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
LanguageModelChatRequestOptions,
77
LanguageModelChatResponse,
88
} from "vscode";
9-
import Configuration from "../configuration";
109
import { AiConfig, AiProvider } from "./aiConfig";
1110

1211
export function chatRequest(

0 commit comments

Comments
 (0)