Skip to content

Commit 5a394d2

Browse files
authored
[inference] Partial revert of #1199, cleaner implem (#1201)
1 parent 62e314a commit 5a394d2

File tree

3 files changed

+123
-2
lines changed

3 files changed

+123
-2
lines changed

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ function makeUrl(params: {
243243
}
244244
default: {
245245
const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE.replaceAll("{{PROVIDER}}", "hf-inference");
246+
if (params.taskHint && ["feature-extraction", "sentence-similarity"].includes(params.taskHint)) {
247+
/// when deployed on hf-inference, those two tasks are automatically compatible with one another.
248+
return `${baseUrl}/pipeline/${params.taskHint}/${params.model}`;
249+
}
246250
if (params.taskHint === "text-generation" && params.chatCompletion) {
247251
return `${baseUrl}/models/${params.model}/v1/chat/completions`;
248252
}

packages/inference/test/HfInference.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ describe.concurrent("HfInference", () => {
351351
});
352352
expect(response).toEqual(expect.arrayContaining([expect.any(Number)]));
353353
});
354+
it("FeatureExtraction - auto-compatibility sentence similarity", async () => {
355+
const response = await hf.featureExtraction({
356+
model: "sentence-transformers/paraphrase-xlm-r-multilingual-v1",
357+
inputs: "That is a happy person",
358+
});
359+
360+
expect(response.length).toBeGreaterThan(10);
361+
expect(response).toEqual(expect.arrayContaining([expect.any(Number)]));
362+
});
354363
it("FeatureExtraction - facebook/bart-base", async () => {
355364
const response = await hf.featureExtraction({
356365
model: "facebook/bart-base",

packages/inference/test/tapes.json

Lines changed: 110 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)