Skip to content

Commit f1204ce

Browse files
authored
Move automodel version split further up (#2676)
1 parent 234760e commit f1204ce

File tree

1 file changed

+144
-119
lines changed

1 file changed

+144
-119
lines changed

extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts

Lines changed: 144 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,20 @@ export class DataExtensionsEditorView extends AbstractWebview<
160160

161161
break;
162162
case "generateExternalApiFromLlm":
163-
await this.generateModeledMethodsFromLlm(
164-
msg.externalApiUsages,
165-
msg.modeledMethods,
166-
);
167-
163+
if (useLlmGenerationV2()) {
164+
await this.generateModeledMethodsFromLlmV2(
165+
msg.externalApiUsages,
166+
msg.modeledMethods,
167+
);
168+
} else {
169+
await this.generateModeledMethodsFromLlmV1(
170+
msg.externalApiUsages,
171+
msg.modeledMethods,
172+
);
173+
}
168174
break;
169175
case "modelDependency":
170176
await this.modelDependency();
171-
172177
break;
173178
case "switchMode":
174179
this.mode = msg.mode;
@@ -362,7 +367,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
362367
);
363368
}
364369

365-
private async generateModeledMethodsFromLlm(
370+
private async generateModeledMethodsFromLlmV1(
366371
externalApiUsages: ExternalApiUsage[],
367372
modeledMethods: Record<string, ModeledMethod>,
368373
): Promise<void> {
@@ -375,135 +380,155 @@ export class DataExtensionsEditorView extends AbstractWebview<
375380
message: "Retrieving usages",
376381
});
377382

378-
let predictedModeledMethods: Record<string, ModeledMethod>;
383+
const usages = await getAutoModelUsages({
384+
cliServer: this.cliServer,
385+
queryRunner: this.queryRunner,
386+
queryStorageDir: this.queryStorageDir,
387+
queryDir: this.queryDir,
388+
databaseItem: this.databaseItem,
389+
progress: (update) => progress({ ...update, maxStep }),
390+
});
379391

380-
if (useLlmGenerationV2()) {
381-
// Fetch the candidates to send to the model
382-
const candidateMethods = getCandidates(
383-
this.mode,
384-
externalApiUsages,
385-
modeledMethods,
386-
);
392+
progress({
393+
step: 1800,
394+
maxStep,
395+
message: "Creating request",
396+
});
387397

388-
// If there are no candidates, there is nothing to model and we just return
389-
if (candidateMethods.length === 0) {
390-
void extLogger.log("No candidates to model. Stopping.");
391-
return;
392-
}
398+
const request = createAutoModelRequest(
399+
this.databaseItem.language,
400+
externalApiUsages,
401+
modeledMethods,
402+
usages,
403+
this.mode,
404+
);
393405

394-
const usages = await runAutoModelQueries({
395-
mode: this.mode,
396-
candidateMethods,
397-
cliServer: this.cliServer,
398-
queryRunner: this.queryRunner,
399-
queryStorageDir: this.queryStorageDir,
400-
databaseItem: this.databaseItem,
401-
progress: (update) => progress({ ...update, maxStep }),
402-
});
403-
if (!usages) {
404-
return;
405-
}
406+
progress({
407+
step: 2000,
408+
maxStep,
409+
message: "Sending request",
410+
});
406411

407-
progress({
408-
step: 1800,
409-
maxStep,
410-
message: "Creating request",
411-
});
412+
const response = await this.callAutoModelApi(request);
413+
if (!response) {
414+
return;
415+
}
412416

413-
const request = await createAutoModelV2Request(this.mode, usages);
417+
progress({
418+
step: 2500,
419+
maxStep,
420+
message: "Parsing response",
421+
});
414422

415-
progress({
416-
step: 2000,
417-
maxStep,
418-
message: "Sending request",
419-
});
423+
const predictedModeledMethods = parsePredictedClassifications(
424+
response.predicted || [],
425+
);
420426

421-
const response = await this.callAutoModelApiV2(request);
422-
if (!response) {
423-
return;
424-
}
427+
progress({
428+
step: 2800,
429+
maxStep,
430+
message: "Applying results",
431+
});
425432

426-
progress({
427-
step: 2500,
428-
maxStep,
429-
message: "Parsing response",
430-
});
433+
await this.postMessage({
434+
t: "addModeledMethods",
435+
modeledMethods: predictedModeledMethods,
436+
});
437+
});
438+
}
431439

432-
const models = loadYaml(response.models, {
433-
filename: "auto-model.yml",
434-
});
440+
private async generateModeledMethodsFromLlmV2(
441+
externalApiUsages: ExternalApiUsage[],
442+
modeledMethods: Record<string, ModeledMethod>,
443+
): Promise<void> {
444+
await withProgress(async (progress) => {
445+
const maxStep = 3000;
435446

436-
const loadedMethods = loadDataExtensionYaml(models);
437-
if (!loadedMethods) {
438-
return;
439-
}
447+
progress({
448+
step: 0,
449+
maxStep,
450+
message: "Retrieving usages",
451+
});
440452

441-
// Any candidate that was part of the response is a negative result
442-
// meaning that the canidate is not a sink for the kinds that the LLM is checking for.
443-
// For now we model this as a sink neutral method, however this is subject
444-
// to discussion.
445-
for (const candidate of candidateMethods) {
446-
if (!(candidate.signature in loadedMethods)) {
447-
loadedMethods[candidate.signature] = {
448-
type: "neutral",
449-
kind: "sink",
450-
input: "",
451-
output: "",
452-
provenance: "ai-generated",
453-
signature: candidate.signature,
454-
packageName: candidate.packageName,
455-
typeName: candidate.typeName,
456-
methodName: candidate.methodName,
457-
methodParameters: candidate.methodParameters,
458-
};
459-
}
460-
}
453+
// Fetch the candidates to send to the model
454+
const candidateMethods = getCandidates(
455+
this.mode,
456+
externalApiUsages,
457+
modeledMethods,
458+
);
461459

462-
predictedModeledMethods = loadedMethods;
463-
} else {
464-
const usages = await getAutoModelUsages({
465-
cliServer: this.cliServer,
466-
queryRunner: this.queryRunner,
467-
queryStorageDir: this.queryStorageDir,
468-
queryDir: this.queryDir,
469-
databaseItem: this.databaseItem,
470-
progress: (update) => progress({ ...update, maxStep }),
471-
});
460+
// If there are no candidates, there is nothing to model and we just return
461+
if (candidateMethods.length === 0) {
462+
void extLogger.log("No candidates to model. Stopping.");
463+
return;
464+
}
472465

473-
progress({
474-
step: 1800,
475-
maxStep,
476-
message: "Creating request",
477-
});
466+
const usages = await runAutoModelQueries({
467+
mode: this.mode,
468+
candidateMethods,
469+
cliServer: this.cliServer,
470+
queryRunner: this.queryRunner,
471+
queryStorageDir: this.queryStorageDir,
472+
databaseItem: this.databaseItem,
473+
progress: (update) => progress({ ...update, maxStep }),
474+
});
475+
if (!usages) {
476+
return;
477+
}
478478

479-
const request = createAutoModelRequest(
480-
this.databaseItem.language,
481-
externalApiUsages,
482-
modeledMethods,
483-
usages,
484-
this.mode,
485-
);
479+
progress({
480+
step: 1800,
481+
maxStep,
482+
message: "Creating request",
483+
});
486484

487-
progress({
488-
step: 2000,
489-
maxStep,
490-
message: "Sending request",
491-
});
485+
const request = await createAutoModelV2Request(this.mode, usages);
492486

493-
const response = await this.callAutoModelApi(request);
494-
if (!response) {
495-
return;
496-
}
487+
progress({
488+
step: 2000,
489+
maxStep,
490+
message: "Sending request",
491+
});
497492

498-
progress({
499-
step: 2500,
500-
maxStep,
501-
message: "Parsing response",
502-
});
493+
const response = await this.callAutoModelApiV2(request);
494+
if (!response) {
495+
return;
496+
}
503497

504-
predictedModeledMethods = parsePredictedClassifications(
505-
response.predicted || [],
506-
);
498+
progress({
499+
step: 2500,
500+
maxStep,
501+
message: "Parsing response",
502+
});
503+
504+
const models = loadYaml(response.models, {
505+
filename: "auto-model.yml",
506+
});
507+
508+
const loadedMethods = loadDataExtensionYaml(models);
509+
if (!loadedMethods) {
510+
return;
511+
}
512+
513+
// Any candidate that was part of the response is a negative result
514+
// meaning that the canidate is not a sink for the kinds that the LLM is checking for.
515+
// For now we model this as a sink neutral method, however this is subject
516+
// to discussion.
517+
for (const candidate of candidateMethods) {
518+
if (!(candidate.signature in loadedMethods)) {
519+
loadedMethods[candidate.signature] = {
520+
type: "neutral",
521+
kind: "sink",
522+
input: "",
523+
output: "",
524+
provenance: "ai-generated",
525+
signature: candidate.signature,
526+
packageName: candidate.packageName,
527+
typeName: candidate.typeName,
528+
methodName: candidate.methodName,
529+
methodParameters: candidate.methodParameters,
530+
};
531+
}
507532
}
508533

509534
progress({
@@ -514,7 +539,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
514539

515540
await this.postMessage({
516541
t: "addModeledMethods",
517-
modeledMethods: predictedModeledMethods,
542+
modeledMethods: loadedMethods,
518543
});
519544
});
520545
}

0 commit comments

Comments
 (0)