Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add inferenceProvider filter when listing models #1198

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/hub/src/lib/list-models.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,39 @@ describe("listModels", () => {

expect(count).to.equal(10);
});

it("should search model by inference provider", async () => {
let count = 0;
for await (const entry of listModels({
search: { inferenceProviders: ["together"] },
additionalFields: ["inferenceProviderMapping"],
limit: 10,
})) {
count++;
if (Array.isArray(entry.inferenceProviderMapping)) {
expect(entry.inferenceProviderMapping.map(({ provider }) => provider)).to.include("together");
}
}

expect(count).to.equal(10);
});

it("should search model by several inference providers", async () => {
let count = 0;
const inferenceProviders = ["together", "replicate"];
for await (const entry of listModels({
search: { inferenceProviders },
additionalFields: ["inferenceProviderMapping"],
limit: 10,
})) {
count++;
if (Array.isArray(entry.inferenceProviderMapping)) {
expect(
entry.inferenceProviderMapping.filter(({ provider }) => inferenceProviders.includes(provider)).length
).toBeGreaterThan(0);
}
}

expect(count).to.equal(10);
});
});
7 changes: 7 additions & 0 deletions packages/hub/src/lib/list-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export async function* listModels<
owner?: string;
task?: PipelineType;
tags?: string[];
/**
* Will search for models that have one of the inference providers in the list.
*/
inferenceProviders?: string[];
};
hubUrl?: string;
additionalFields?: T[];
Expand All @@ -84,6 +88,9 @@ export async function* listModels<
...(params?.search?.owner ? { author: params.search.owner } : undefined),
...(params?.search?.task ? { pipeline_tag: params.search.task } : undefined),
...(params?.search?.query ? { search: params.search.query } : undefined),
...(params?.search?.inferenceProviders
? { inference_provider: params.search.inferenceProviders.join(",") }
: undefined),
}),
...(params?.search?.tags?.map((tag) => ["filter", tag]) ?? []),
...MODEL_EXPAND_KEYS.map((val) => ["expand", val] satisfies [string, string]),
Expand Down