Skip to content

Commit 90c8391

Browse files
committed
Sort methods sent to LLM the same way as the UI
This changes the sorting of the methods sent to LLM to match the order shown in the data extensions editor. This will ensure that the methods which are shown first in the data extensions editor are also modeled first.
1 parent a8aee6a commit 90c8391

File tree

3 files changed

+67
-53
lines changed

3 files changed

+67
-53
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
ModelRequest,
88
} from "./auto-model-api";
99
import type { UsageSnippetsBySignature } from "./auto-model-usages-query";
10+
import { groupMethods, sortGroupNames, sortMethods } from "./shared/sorting";
11+
import { Mode } from "./shared/mode";
1012

1113
// Soft limit on the number of candidates to send to the model.
1214
// Note that the model may return fewer than this number of candidates.
@@ -19,18 +21,22 @@ export function createAutoModelRequest(
1921
externalApiUsages: ExternalApiUsage[],
2022
modeledMethods: Record<string, ModeledMethod>,
2123
usages: UsageSnippetsBySignature,
24+
mode: Mode,
2225
): ModelRequest {
2326
const request: ModelRequest = {
2427
language,
2528
samples: [],
2629
candidates: [],
2730
};
2831

29-
// Sort by number of usages so we always send the most used methods first
30-
externalApiUsages = [...externalApiUsages];
31-
externalApiUsages.sort((a, b) => b.usages.length - a.usages.length);
32+
// Sort the same way as the UI so we send the first ones listed in the UI first
33+
const grouped = groupMethods(externalApiUsages, mode);
34+
const sortedGroupNames = sortGroupNames(grouped);
35+
const sortedExternalApiUsages = sortedGroupNames.flatMap((name) =>
36+
sortMethods(grouped[name]),
37+
);
3238

33-
for (const externalApiUsage of externalApiUsages) {
39+
for (const externalApiUsage of sortedExternalApiUsages) {
3440
const modeledMethod: ModeledMethod = modeledMethods[
3541
externalApiUsage.signature
3642
] ?? {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
457457
externalApiUsages,
458458
modeledMethods,
459459
usages,
460+
this.mode,
460461
);
461462

462463
await this.showProgress({

extensions/ql-vscode/test/unit-tests/data-extensions-editor/auto-model.test.ts

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ClassificationType,
1010
Method,
1111
} from "../../../src/data-extensions-editor/auto-model-api";
12+
import { Mode } from "../../../src/data-extensions-editor/shared/mode";
1213

1314
describe("createAutoModelRequest", () => {
1415
const externalApiUsages: ExternalApiUsage[] = [
@@ -259,7 +260,13 @@ describe("createAutoModelRequest", () => {
259260

260261
it("creates a matching request", () => {
261262
expect(
262-
createAutoModelRequest("java", externalApiUsages, modeledMethods, usages),
263+
createAutoModelRequest(
264+
"java",
265+
externalApiUsages,
266+
modeledMethods,
267+
usages,
268+
Mode.Application,
269+
),
263270
).toEqual({
264271
language: "java",
265272
samples: [
@@ -341,41 +348,41 @@ describe("createAutoModelRequest", () => {
341348
classification: undefined,
342349
},
343350
{
344-
package: "org.springframework.boot",
345-
type: "SpringApplication",
346-
name: "run",
347-
signature: "(Class,String[])",
348-
usages:
349-
usages[
350-
"org.springframework.boot.SpringApplication#run(Class,String[])"
351-
],
351+
package: "org.sql2o",
352+
type: "Sql2o",
353+
name: "Sql2o",
354+
signature: "(String,String,String)",
355+
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
352356
input: "Argument[this]",
353357
classification: undefined,
354358
},
355359
{
356-
package: "org.springframework.boot",
357-
type: "SpringApplication",
358-
name: "run",
359-
signature: "(Class,String[])",
360-
usages:
361-
usages[
362-
"org.springframework.boot.SpringApplication#run(Class,String[])"
363-
],
360+
package: "org.sql2o",
361+
type: "Sql2o",
362+
name: "Sql2o",
363+
signature: "(String,String,String)",
364+
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
364365
input: "Argument[0]",
365366
classification: undefined,
366367
},
367368
{
368-
package: "org.springframework.boot",
369-
type: "SpringApplication",
370-
name: "run",
371-
signature: "(Class,String[])",
372-
usages:
373-
usages[
374-
"org.springframework.boot.SpringApplication#run(Class,String[])"
375-
],
369+
package: "org.sql2o",
370+
type: "Sql2o",
371+
name: "Sql2o",
372+
signature: "(String,String,String)",
373+
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
376374
input: "Argument[1]",
377375
classification: undefined,
378376
},
377+
{
378+
package: "org.sql2o",
379+
type: "Sql2o",
380+
name: "Sql2o",
381+
signature: "(String,String,String)",
382+
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
383+
input: "Argument[2]",
384+
classification: undefined,
385+
},
379386
{
380387
package: "java.io",
381388
type: "PrintStream",
@@ -395,41 +402,41 @@ describe("createAutoModelRequest", () => {
395402
classification: undefined,
396403
},
397404
{
398-
package: "org.sql2o",
399-
type: "Sql2o",
400-
name: "Sql2o",
401-
signature: "(String,String,String)",
402-
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
405+
package: "org.springframework.boot",
406+
type: "SpringApplication",
407+
name: "run",
408+
signature: "(Class,String[])",
409+
usages:
410+
usages[
411+
"org.springframework.boot.SpringApplication#run(Class,String[])"
412+
],
403413
input: "Argument[this]",
404414
classification: undefined,
405415
},
406416
{
407-
package: "org.sql2o",
408-
type: "Sql2o",
409-
name: "Sql2o",
410-
signature: "(String,String,String)",
411-
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
417+
package: "org.springframework.boot",
418+
type: "SpringApplication",
419+
name: "run",
420+
signature: "(Class,String[])",
421+
usages:
422+
usages[
423+
"org.springframework.boot.SpringApplication#run(Class,String[])"
424+
],
412425
input: "Argument[0]",
413426
classification: undefined,
414427
},
415428
{
416-
package: "org.sql2o",
417-
type: "Sql2o",
418-
name: "Sql2o",
419-
signature: "(String,String,String)",
420-
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
429+
package: "org.springframework.boot",
430+
type: "SpringApplication",
431+
name: "run",
432+
signature: "(Class,String[])",
433+
usages:
434+
usages[
435+
"org.springframework.boot.SpringApplication#run(Class,String[])"
436+
],
421437
input: "Argument[1]",
422438
classification: undefined,
423439
},
424-
{
425-
package: "org.sql2o",
426-
type: "Sql2o",
427-
name: "Sql2o",
428-
signature: "(String,String,String)",
429-
usages: usages["org.sql2o.Sql2o#Sql2o(String,String,String)"],
430-
input: "Argument[2]",
431-
classification: undefined,
432-
},
433440
],
434441
});
435442
});

0 commit comments

Comments
 (0)