@@ -17,6 +17,8 @@ let client: LanguageClient;
1717const configName = 'sublimeSecurity.messageQueryLanguage' ;
1818const languageID = 'messageQueryLanguage' ;
1919
20+ type OpenAIClientAndCompletionModel = { client : OpenAIApi , completionModel : string } ;
21+
2022class 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
210213export 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