Skip to content

Commit 76fb55f

Browse files
committed
Tweak candidate selection:
- At most 6 usages. - Send -1 for `this` argument. - Do not send only some arguments for candidate or sample.
1 parent a98e31f commit 76fb55f

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88
} from "./auto-model-api";
99
import type { UsageSnippetsBySignature } from "./auto-model-usages-query";
1010

11+
// Soft limit on the number of candidates to send to the model.
12+
// Note that the model may return fewer than this number of candidates.
13+
const candidateLimit = 20;
14+
// Soft limit on the number of samples to send to the model.
15+
const sampleLimit = 100;
16+
1117
export function createAutoModelRequest(
1218
language: string,
1319
externalApiUsages: ExternalApiUsage[],
@@ -40,8 +46,10 @@ export function createAutoModelRequest(
4046
? 0
4147
: externalApiUsage.methodParameters.split(",").length;
4248

49+
const candidates = [];
50+
const samples = [];
4351
for (
44-
let argumentIndex = 0;
52+
let argumentIndex = -1; // Start at -1 which means `this` as in `this.method()`
4553
argumentIndex < numberOfArguments;
4654
argumentIndex++
4755
) {
@@ -54,21 +62,29 @@ export function createAutoModelRequest(
5462
modeledMethod.type === "none"
5563
? undefined
5664
: toMethodClassification(modeledMethod),
57-
usages: usagesForMethod.slice(0, 10),
65+
usages: usagesForMethod.slice(0, 6), // At most 6 usages per argument
5866
input: `Argument[${argumentIndex}]`,
5967
};
6068

61-
if (modeledMethod.type === "none") {
62-
request.candidates.push(method);
69+
// Candidates are methods that are not currently modeled in this model file or in any other model file.
70+
if (modeledMethod.type === "none" && !externalApiUsage.supported) {
71+
candidates.push(method);
6372
} else {
64-
request.samples.push(method);
73+
samples.push(method);
6574
}
6675
}
76+
// If there is room for at least one candidate, add all candidates.
77+
// This ensures that we send all arguments for a method together.
78+
// NOTE: this might go above the candidate limit, but that's okay.
79+
if (request.candidates.length < candidateLimit) {
80+
request.candidates.push(...candidates);
81+
}
82+
// Same for samples
83+
if (request.samples.length < sampleLimit) {
84+
request.samples.push(...samples);
85+
}
6786
}
6887

69-
request.candidates = request.candidates.slice(0, 20);
70-
request.samples = request.samples.slice(0, 100);
71-
7288
return request;
7389
}
7490

0 commit comments

Comments
 (0)