Skip to content

Commit

Permalink
[inference] Partial revert of #1199, cleaner implem (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-c authored Feb 14, 2025
1 parent 62e314a commit 5a394d2
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/inference/src/lib/makeRequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ function makeUrl(params: {
}
default: {
const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE.replaceAll("{{PROVIDER}}", "hf-inference");
if (params.taskHint && ["feature-extraction", "sentence-similarity"].includes(params.taskHint)) {
/// when deployed on hf-inference, those two tasks are automatically compatible with one another.
return `${baseUrl}/pipeline/${params.taskHint}/${params.model}`;
}
if (params.taskHint === "text-generation" && params.chatCompletion) {
return `${baseUrl}/models/${params.model}/v1/chat/completions`;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/inference/test/HfInference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ describe.concurrent("HfInference", () => {
});
expect(response).toEqual(expect.arrayContaining([expect.any(Number)]));
});
it("FeatureExtraction - auto-compatibility sentence similarity", async () => {
const response = await hf.featureExtraction({
model: "sentence-transformers/paraphrase-xlm-r-multilingual-v1",
inputs: "That is a happy person",
});

expect(response.length).toBeGreaterThan(10);
expect(response).toEqual(expect.arrayContaining([expect.any(Number)]));
});
it("FeatureExtraction - facebook/bart-base", async () => {
const response = await hf.featureExtraction({
model: "facebook/bart-base",
Expand Down
112 changes: 110 additions & 2 deletions packages/inference/test/tapes.json

Large diffs are not rendered by default.

0 comments on commit 5a394d2

Please sign in to comment.