Skip to content

Commit 0cc8e68

Browse files
committed
Extract modeling of specific set of candidates into its own function
1 parent 7588271 commit 0cc8e68

File tree

1 file changed

+78
-69
lines changed

1 file changed

+78
-69
lines changed

extensions/ql-vscode/src/data-extensions-editor/auto-modeler.ts

Lines changed: 78 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ExternalApiUsage } from "./external-api-usage";
1+
import { ExternalApiUsage, MethodSignature } from "./external-api-usage";
22
import { ModeledMethod } from "./modeled-method";
33
import { extLogger } from "../common/logging/vscode";
44
import { load as loadYaml } from "js-yaml";
5-
import { withProgress } from "../common/vscode/progress";
5+
import { ProgressCallback, withProgress } from "../common/vscode/progress";
66
import { createAutoModelV2Request, getCandidates } from "./auto-model-v2";
77
import { runAutoModelQueries } from "./auto-model-codeml-queries";
88
import { loadDataExtensionYaml } from "./yaml";
@@ -33,10 +33,10 @@ export class AutoModeler {
3333
modeledMethods: Record<string, ModeledMethod>,
3434
mode: Mode,
3535
): Promise<void> {
36-
await this.model(externalApiUsages, modeledMethods, mode);
36+
await this.modelDependency(externalApiUsages, modeledMethods, mode);
3737
}
3838

39-
private async model(
39+
private async modelDependency(
4040
externalApiUsages: ExternalApiUsage[],
4141
modeledMethods: Record<string, ModeledMethod>,
4242
mode: Mode,
@@ -63,82 +63,91 @@ export class AutoModeler {
6363
return;
6464
}
6565

66-
const usages = await runAutoModelQueries({
67-
mode,
68-
candidateMethods,
69-
cliServer: this.cliServer,
70-
queryRunner: this.queryRunner,
71-
queryStorageDir: this.queryStorageDir,
72-
databaseItem: this.databaseItem,
73-
progress: (update) => progress({ ...update, maxStep }),
74-
});
75-
if (!usages) {
76-
return;
77-
}
66+
await this.modelCandidates(candidateMethods, mode, progress, maxStep);
67+
});
68+
}
7869

79-
progress({
80-
step: 1800,
81-
maxStep,
82-
message: "Creating request",
83-
});
70+
private async modelCandidates(
71+
candidateMethods: MethodSignature[],
72+
mode: Mode,
73+
progress: ProgressCallback,
74+
maxStep: number,
75+
): Promise<void> {
76+
const usages = await runAutoModelQueries({
77+
mode,
78+
candidateMethods,
79+
cliServer: this.cliServer,
80+
queryRunner: this.queryRunner,
81+
queryStorageDir: this.queryStorageDir,
82+
databaseItem: this.databaseItem,
83+
progress: (update) => progress({ ...update, maxStep }),
84+
});
85+
if (!usages) {
86+
return;
87+
}
8488

85-
const request = await createAutoModelV2Request(mode, usages);
89+
progress({
90+
step: 1800,
91+
maxStep,
92+
message: "Creating request",
93+
});
8694

87-
progress({
88-
step: 2000,
89-
maxStep,
90-
message: "Sending request",
91-
});
95+
const request = await createAutoModelV2Request(mode, usages);
9296

93-
const response = await this.callAutoModelApi(request);
94-
if (!response) {
95-
return;
96-
}
97+
progress({
98+
step: 2000,
99+
maxStep,
100+
message: "Sending request",
101+
});
97102

98-
progress({
99-
step: 2500,
100-
maxStep,
101-
message: "Parsing response",
102-
});
103+
const response = await this.callAutoModelApi(request);
104+
if (!response) {
105+
return;
106+
}
103107

104-
const models = loadYaml(response.models, {
105-
filename: "auto-model.yml",
106-
});
108+
progress({
109+
step: 2500,
110+
maxStep,
111+
message: "Parsing response",
112+
});
107113

108-
const loadedMethods = loadDataExtensionYaml(models);
109-
if (!loadedMethods) {
110-
return;
111-
}
114+
const models = loadYaml(response.models, {
115+
filename: "auto-model.yml",
116+
});
112117

113-
// Any candidate that was part of the response is a negative result
114-
// meaning that the canidate is not a sink for the kinds that the LLM is checking for.
115-
// For now we model this as a sink neutral method, however this is subject
116-
// to discussion.
117-
for (const candidate of candidateMethods) {
118-
if (!(candidate.signature in loadedMethods)) {
119-
loadedMethods[candidate.signature] = {
120-
type: "neutral",
121-
kind: "sink",
122-
input: "",
123-
output: "",
124-
provenance: "ai-generated",
125-
signature: candidate.signature,
126-
packageName: candidate.packageName,
127-
typeName: candidate.typeName,
128-
methodName: candidate.methodName,
129-
methodParameters: candidate.methodParameters,
130-
};
131-
}
132-
}
118+
const loadedMethods = loadDataExtensionYaml(models);
119+
if (!loadedMethods) {
120+
return;
121+
}
133122

134-
progress({
135-
step: 2800,
136-
maxStep,
137-
message: "Applying results",
138-
});
123+
// Any candidate that was part of the response is a negative result
124+
// meaning that the canidate is not a sink for the kinds that the LLM is checking for.
125+
// For now we model this as a sink neutral method, however this is subject
126+
// to discussion.
127+
for (const candidate of candidateMethods) {
128+
if (!(candidate.signature in loadedMethods)) {
129+
loadedMethods[candidate.signature] = {
130+
type: "neutral",
131+
kind: "sink",
132+
input: "",
133+
output: "",
134+
provenance: "ai-generated",
135+
signature: candidate.signature,
136+
packageName: candidate.packageName,
137+
typeName: candidate.typeName,
138+
methodName: candidate.methodName,
139+
methodParameters: candidate.methodParameters,
140+
};
141+
}
142+
}
139143

140-
await this.addModeledMethods(loadedMethods);
144+
progress({
145+
step: 2800,
146+
maxStep,
147+
message: "Applying results",
141148
});
149+
150+
await this.addModeledMethods(loadedMethods);
142151
}
143152

144153
private async callAutoModelApi(

0 commit comments

Comments
 (0)