Skip to content

Commit 7dfb0aa

Browse files
authored
Fix completionModel to use config (#4)
1 parent 88998cc commit 7dfb0aa

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"publisher": "SublimeSecurity",
1010
"license": "MIT",
11-
"version": "0.1.0",
11+
"version": "0.1.1",
1212
"icon": "icon.png",
1313
"repository": {
1414
"type": "git",
@@ -127,7 +127,7 @@
127127
"type": "string",
128128
"description": "The model to use for OpenAI code completions",
129129
"title": "Completion Model",
130-
"default": "curie:ft-sublime-security-2023-04-21-20-26-44",
130+
"default": "curie:ft-sublime-security-2023-08-05-00-34-40",
131131
"order": 5
132132
}
133133
}

src/extension.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ let client: LanguageClient;
1717
const configName = 'sublimeSecurity.messageQueryLanguage';
1818
const languageID = 'messageQueryLanguage';
1919

20+
type OpenAIClientAndCompletionModel = {client: OpenAIApi, completionModel: string};
21+
2022
class WebSocketMessageReader implements MessageReader {
2123
private errorEmitter = new Emitter<Error>();
2224
private closeEmitter = new Emitter<void>();
@@ -181,7 +183,7 @@ function deactivateLanguageServer(): Thenable<void> | undefined {
181183
return client.stop();
182184
}
183185

184-
function getOpenAIClient(): OpenAIApi | undefined {
186+
function getOpenAIClient(): OpenAIClientAndCompletionModel | undefined {
185187
const openAIConfigName = configName + ".openAI";
186188
const config = vscode.workspace.getConfiguration(openAIConfigName);
187189
const apiKey = config.get('apiKey');
@@ -202,13 +204,14 @@ function getOpenAIClient(): OpenAIApi | undefined {
202204
return;
203205
}
204206

205-
return new OpenAIApi(new Configuration({
206-
apiKey: apiKey as string,
207-
}));
207+
return {
208+
client: new OpenAIApi(new Configuration({apiKey: apiKey as string})),
209+
completionModel: completionModel as string,
210+
};
208211
}
209212

210213
export function activateOpenAI(context: vscode.ExtensionContext) {
211-
let openAIClient: OpenAIApi | undefined = undefined;
214+
let clientAndModel: OpenAIClientAndCompletionModel | undefined = undefined;
212215
let loadedClient = false;
213216

214217
vscode.workspace.onDidChangeTextDocument(handleTextDocumentChange, null, context.subscriptions);
@@ -227,10 +230,10 @@ export function activateOpenAI(context: vscode.ExtensionContext) {
227230
// Lazily load the OpenAI client after commments are triggered
228231
if (!loadedClient) {
229232
loadedClient = true;
230-
openAIClient = getOpenAIClient();
233+
clientAndModel = getOpenAIClient();
231234
}
232235

233-
if (!openAIClient) {
236+
if (!clientAndModel) {
234237
return;
235238
}
236239

@@ -256,9 +259,9 @@ export function activateOpenAI(context: vscode.ExtensionContext) {
256259
}
257260

258261
async function requestMqlTranslation(comment: string): Promise<string> {
259-
return openAIClient
262+
return clientAndModel.client
260263
.createCompletion({
261-
model: "curie:ft-sublime-security-2023-08-05-00-34-40",
264+
model: clientAndModel.completionModel,
262265
max_tokens: 128,
263266
temperature: 0.3,
264267
stop: ["\n"],

0 commit comments

Comments
 (0)