Skip to content

Commit d895dae

Browse files
coyotte508julien-c
andauthored
✨ Allow search on model name (#507)
For #506 ```ts for await (const entry of listModels({ search: { query: "t5" }, limit: 10, })) { count++; expect(entry.name).to.include("t5"); } ``` cc @julien-c @Wauplin if you have ideas about the parameter name. It's `search.query`, maybe `search.name` or `search.nameMatch`? or `search.search`... --------- Co-authored-by: Julien Chaumond <[email protected]>
1 parent a933c4a commit d895dae

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

packages/hub/src/lib/list-datasets.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export async function* listDatasets<
4848
const T extends Exclude<(typeof EXPANDABLE_KEYS)[number], (typeof EXPAND_KEYS)[number]> = never,
4949
>(params?: {
5050
search?: {
51+
/**
52+
* Will search in the dataset name for matches
53+
*/
54+
query?: string;
5155
owner?: string;
5256
tags?: string[];
5357
};
@@ -69,6 +73,7 @@ export async function* listDatasets<
6973
...Object.entries({
7074
limit: String(Math.min(totalToFetch, 500)),
7175
...(params?.search?.owner ? { author: params.search.owner } : undefined),
76+
...(params?.search?.query ? { search: params.search.query } : undefined),
7277
}),
7378
...(params?.search?.tags?.map((tag) => ["filter", tag]) ?? []),
7479
...EXPAND_KEYS.map((val) => ["expand", val] satisfies [string, string]),

packages/hub/src/lib/list-models.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,17 @@ describe("listModels", () => {
6767

6868
expect(count).to.equal(2);
6969
});
70+
71+
it("should search model by name", async () => {
72+
let count = 0;
73+
for await (const entry of listModels({
74+
search: { query: "t5" },
75+
limit: 10,
76+
})) {
77+
count++;
78+
expect(entry.name).to.include("t5");
79+
}
80+
81+
expect(count).to.equal(10);
82+
});
7083
});

packages/hub/src/lib/list-models.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export async function* listModels<
5454
const T extends Exclude<(typeof EXPANDABLE_KEYS)[number], (typeof EXPAND_KEYS)[number]> = never,
5555
>(params?: {
5656
search?: {
57+
/**
58+
* Will search in the model name for matches
59+
*/
60+
query?: string;
5761
owner?: string;
5862
task?: PipelineType;
5963
tags?: string[];
@@ -77,6 +81,7 @@ export async function* listModels<
7781
limit: String(Math.min(totalToFetch, 500)),
7882
...(params?.search?.owner ? { author: params.search.owner } : undefined),
7983
...(params?.search?.task ? { pipeline_tag: params.search.task } : undefined),
84+
...(params?.search?.query ? { search: params.search.query } : undefined),
8085
}),
8186
...(params?.search?.tags?.map((tag) => ["filter", tag]) ?? []),
8287
...EXPAND_KEYS.map((val) => ["expand", val] satisfies [string, string]),

packages/hub/src/lib/list-spaces.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export async function* listSpaces<
4040
const T extends Exclude<(typeof EXPANDABLE_KEYS)[number], (typeof EXPAND_KEYS)[number]> = never,
4141
>(params?: {
4242
search?: {
43+
/**
44+
* Will search in the space name for matches
45+
*/
46+
query?: string;
4347
owner?: string;
4448
tags?: string[];
4549
};
@@ -56,7 +60,11 @@ export async function* listSpaces<
5660
}): AsyncGenerator<SpaceEntry> {
5761
checkCredentials(params?.credentials);
5862
const search = new URLSearchParams([
59-
...Object.entries({ limit: "500", ...(params?.search?.owner ? { author: params.search.owner } : undefined) }),
63+
...Object.entries({
64+
limit: "500",
65+
...(params?.search?.owner ? { author: params.search.owner } : undefined),
66+
...(params?.search?.query ? { search: params.search.query } : undefined),
67+
}),
6068
...(params?.search?.tags?.map((tag) => ["filter", tag]) ?? []),
6169
...[...EXPAND_KEYS, ...(params?.additionalFields ?? [])].map((val) => ["expand", val] satisfies [string, string]),
6270
]).toString();

0 commit comments

Comments
 (0)