Skip to content

Commit 3ac87a3

Browse files
Copilotpelikhan
andauthored
Add --filter-model option to test command for filtering by script model (#1835)
* Initial plan * Add --filter-model option to test command for filtering by script model Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Successfully implemented and tested --filter-model option for test command Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Remove accidentally committed files from .genaiscript folder Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: Peli de Halleux <pelikhan@users.noreply.github.com>
1 parent d7d9ccb commit 3ac87a3

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ temp/
88
__pycache__/
99
packages/sample/*.slides.md
1010
packages/**/.genaiscript/
11+
.genaiscript/stats/
12+
.genaiscript/test-runs/
13+
.genaiscript/tests/
1114

1215
vscode-extension-samples/
1316
.DS_Store

packages/cli/src/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export async function cli(): Promise<void> {
281281
.option("--out-summary <file>", "append output summary in file");
282282
addGroupsOptions(testRun)
283283
.option("--test-timeout <number>", "test timeout in seconds")
284+
.option("--filter-model <string>", "filter scripts by model specified in script() function")
284285
.action(scriptsTest); // Action to run the tests
285286

286287
// List available tests
@@ -289,7 +290,9 @@ export async function cli(): Promise<void> {
289290
.alias("ls")
290291
.description("List available tests in workspace")
291292
.option("--redteam", "list red team tests");
292-
addGroupsOptions(testList).action(scriptTestList); // Action to list the tests
293+
addGroupsOptions(testList)
294+
.option("--filter-model <string>", "filter scripts by model specified in script() function")
295+
.action(scriptTestList); // Action to list the tests
293296

294297
// Launch test viewer
295298
test.command("view").description("Launch test viewer").action(scriptTestsView); // Action to view the tests

packages/cli/src/test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ async function listTests(options: {
614614
ids?: string[];
615615
groups?: string[];
616616
redteam?: boolean;
617+
filterModel?: string;
617618
}): Promise<PromptScript[]> {
618619
const prj = await buildProject();
619620
const scripts = filterScripts(prj.scripts, {
@@ -644,6 +645,7 @@ export async function scriptsTest(
644645
testDelay?: string;
645646
groups?: string[];
646647
maxConcurrency?: string;
648+
filterModel?: string;
647649
},
648650
) {
649651
const canceller = createCancellationController();
@@ -667,7 +669,7 @@ export async function scriptsTest(
667669
* @param options - Options to filter the scripts by groups or redteam flag.
668670
* Filters the scripts by groups and whether they are for redteam testing.
669671
*/
670-
export async function scriptTestList(options: { groups?: string[]; redteam?: boolean }) {
672+
export async function scriptTestList(options: { groups?: string[]; redteam?: boolean; filterModel?: string }) {
671673
const scripts = await listTests(options);
672674
console.log(scripts.map((s) => toStringList(s.id, s.filename)).join("\n"));
673675
}

packages/core/src/ast.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface ScriptFilterOptions {
9494
test?: boolean;
9595
redteam?: boolean;
9696
unlisted?: boolean;
97+
filterModel?: string;
9798
}
9899

99100
/**
@@ -106,14 +107,16 @@ export interface ScriptFilterOptions {
106107
* - test: If true, includes only scripts with defined tests.
107108
* - redteam: If true, includes only scripts marked for redteam.
108109
* - unlisted: If true, includes unlisted scripts; otherwise excludes them.
110+
* - filterModel: If provided, includes only scripts that use the specified model.
109111
* @returns A filtered list of scripts matching the given criteria.
110112
*/
111113
export function filterScripts(scripts: PromptScript[], options: ScriptFilterOptions) {
112-
const { ids, groups, test, redteam, unlisted } = options || {};
114+
const { ids, groups, test, redteam, unlisted, filterModel } = options || {};
113115
return scripts
114116
.filter((t) => !test || arrayify(t.tests)?.length)
115117
.filter((t) => !redteam || t.redteam)
116118
.filter((t) => !ids?.length || ids.includes(t.id))
117119
.filter((t) => unlisted || !t.unlisted)
118-
.filter((t) => tagFilter(groups, t.group));
120+
.filter((t) => tagFilter(groups, t.group))
121+
.filter((t) => !filterModel || t.model === filterModel);
119122
}

0 commit comments

Comments
 (0)