1
+ import ollama , { ListResponse } from "ollama" ;
1
2
import * as vscode from "vscode" ;
2
- import { JobManager } from "../config" ;
3
3
import Statement from "../database/statement" ;
4
- import { chatRequest } from "./send" ;
5
- import Configuration from "../configuration" ;
6
- import { getDefaultSchema , findPossibleTables , refsToMarkdown , getSystemStatus , canTalkToDb } from "./context" ;
7
4
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" ;
9
13
10
14
const CHAT_ID = `vscode-db2i.chat` ;
11
15
@@ -32,7 +36,6 @@ export function activateChat(context: vscode.ExtensionContext) {
32
36
let messages : vscode . LanguageModelChatMessage [ ] ;
33
37
34
38
if ( canTalkToDb ( ) ) {
35
-
36
39
const usingSchema = getDefaultSchema ( ) ;
37
40
38
41
switch ( request . command ) {
@@ -107,19 +110,21 @@ export function activateChat(context: vscode.ExtensionContext) {
107
110
return { metadata : { command : "build" } } ;
108
111
}
109
112
} 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
+ ) ;
111
116
}
112
117
} ;
113
118
114
119
const chat = vscode . chat . createChatParticipant ( CHAT_ID , chatHandler ) ;
115
120
chat . iconPath = new vscode . ThemeIcon ( `database` ) ;
116
121
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
122
125
) ;
126
+
127
+ context . subscriptions . push ( chat , changeModelCommand ) ;
123
128
}
124
129
125
130
async function streamModelResponse (
@@ -128,17 +133,20 @@ async function streamModelResponse(
128
133
token : vscode . CancellationToken
129
134
) {
130
135
const chosenProvider = AiConfig . getProvider ( ) ;
136
+ const chosenModel = AiConfig . getModel ( ) ;
131
137
132
138
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
+ ) ;
134
142
stream . button ( {
135
143
command : `vscode-db2i.ai.changeModel` ,
136
144
title : `Select AI Provider and Model` ,
137
145
} ) ;
138
146
return ;
139
147
}
140
148
141
- stream . progress ( `Using ${ chosenProvider } ... ` ) ;
149
+ stream . progress ( `Provider: ${ chosenProvider } Model: ${ chosenModel } ` ) ;
142
150
143
151
return chatRequest ( chosenProvider , messages , { } , token , stream ) ;
144
152
}
@@ -150,33 +158,40 @@ async function selectProviderAndModel() {
150
158
151
159
try {
152
160
ollamaModels = await ollama . list ( ) ;
153
- } catch ( e ) { }
161
+ } catch ( e ) { }
154
162
155
163
const provider = await vscode . window . showQuickPick (
156
164
[
157
165
{ 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
+ ) ,
173
188
] ,
174
189
{
175
190
title : "Select the AI model" ,
176
191
}
177
192
) ;
178
193
179
- if ( provider && ' provider' in provider && ' family' in provider ) {
194
+ if ( provider && " provider" in provider && " family" in provider ) {
180
195
AiConfig . setProvider ( provider . provider ) ;
181
196
AiConfig . setModel ( provider . family ) ;
182
197
}
0 commit comments