Skip to content

Commit 5801e1f

Browse files
committed
Add backward compat test
1 parent d573716 commit 5801e1f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

packages/inference/src/InferenceClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ export class InferenceClientEndpoint {
6666
export interface InferenceClient extends TaskWithNoAccessToken {}
6767

6868
export interface InferenceClientEndpoint extends TaskWithNoAccessTokenNoEndpointUrl {}
69+
70+
/**
71+
* For backward compatibility only.
72+
*/
73+
export class HfInference extends InferenceClient {}

packages/inference/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { InferenceClient, InferenceClientEndpoint } from "./InferenceClient";
1+
export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient";
22
export { InferenceOutputError } from "./lib/InferenceOutputError";
33
export * from "./types";
44
export * from "./tasks";

packages/inference/test/InferenceClient.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { assert, describe, expect, it } from "vitest";
33
import type { ChatCompletionStreamOutput } from "@huggingface/tasks";
44

55
import type { TextToImageArgs } from "../src";
6-
import { chatCompletion, chatCompletionStream, InferenceClient, textGeneration, textToImage } from "../src";
6+
import {
7+
chatCompletion,
8+
chatCompletionStream,
9+
InferenceClient,
10+
textGeneration,
11+
textToImage,
12+
HfInference,
13+
} from "../src";
714
import { textToVideo } from "../src/tasks/cv/textToVideo";
815
import { readTestFile } from "./test-files";
916
import "./vcr";
@@ -20,6 +27,13 @@ if (!env.HF_TOKEN) {
2027
describe.concurrent("InferenceClient", () => {
2128
// Individual tests can be ran without providing an api key, however running all tests without an api key will result in rate limiting error.
2229

30+
describe("backward compatibility", () => {
31+
it("works with old HfInference name", async () => {
32+
const hf = new HfInference(env.HF_TOKEN);
33+
expect("fillMask" in hf).toBe(true);
34+
});
35+
});
36+
2337
describe.concurrent(
2438
"HF Inference",
2539
() => {

0 commit comments

Comments
 (0)