Skip to content

Commit 69ad498

Browse files
viktor2077Wauplin
andauthored
feat. Add text-to-video - Wan2.1-T2V-14B from Novita (#1263)
Co-authored-by: Lucain <[email protected]> Co-authored-by: Lucain <[email protected]>
1 parent 0b13731 commit 69ad498

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

packages/inference/src/providers/novita.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
1818

19-
const NOVITA_API_BASE_URL = "https://api.novita.ai/v3/openai";
19+
const NOVITA_API_BASE_URL = "https://api.novita.ai";
2020

2121
const makeBody = (params: BodyParams): Record<string, unknown> => {
2222
return {
@@ -32,9 +32,11 @@ const makeHeaders = (params: HeaderParams): Record<string, string> => {
3232
const makeUrl = (params: UrlParams): string => {
3333
if (params.task === "text-generation") {
3434
if (params.chatCompletion) {
35-
return `${params.baseUrl}/chat/completions`;
35+
return `${params.baseUrl}/v3/openai/chat/completions`;
3636
}
37-
return `${params.baseUrl}/completions`;
37+
return `${params.baseUrl}/v3/openai/completions`;
38+
} else if (params.task === "text-to-video") {
39+
return `${params.baseUrl}/v3/hf/${params.model}`;
3840
}
3941
return params.baseUrl;
4042
};

packages/inference/src/tasks/cv/textToVideo.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ interface ReplicateOutput {
2020
output: string;
2121
}
2222

23-
const SUPPORTED_PROVIDERS = ["fal-ai", "replicate"] as const satisfies readonly InferenceProvider[];
23+
interface NovitaOutput {
24+
video: {
25+
video_url: string;
26+
};
27+
}
28+
29+
const SUPPORTED_PROVIDERS = ["fal-ai", "novita", "replicate"] as const satisfies readonly InferenceProvider[];
2430

2531
export async function textToVideo(args: TextToVideoArgs, options?: Options): Promise<TextToVideoOutput> {
2632
if (!args.provider || !typedInclude(SUPPORTED_PROVIDERS, args.provider)) {
@@ -30,14 +36,13 @@ export async function textToVideo(args: TextToVideoArgs, options?: Options): Pro
3036
}
3137

3238
const payload =
33-
args.provider === "fal-ai" || args.provider === "replicate"
39+
args.provider === "fal-ai" || args.provider === "replicate" || args.provider === "novita"
3440
? { ...omit(args, ["inputs", "parameters"]), ...args.parameters, prompt: args.inputs }
3541
: args;
36-
const res = await request<FalAiOutput | ReplicateOutput>(payload, {
42+
const res = await request<FalAiOutput | ReplicateOutput | NovitaOutput>(payload, {
3743
...options,
3844
task: "text-to-video",
3945
});
40-
4146
if (args.provider === "fal-ai") {
4247
const isValidOutput =
4348
typeof res === "object" &&
@@ -51,7 +56,22 @@ export async function textToVideo(args: TextToVideoArgs, options?: Options): Pro
5156
if (!isValidOutput) {
5257
throw new InferenceOutputError("Expected { video: { url: string } }");
5358
}
54-
const urlResponse = await fetch(res.video.url);
59+
const urlResponse = await fetch((res as FalAiOutput).video.url);
60+
return await urlResponse.blob();
61+
} else if (args.provider === "novita") {
62+
const isValidOutput =
63+
typeof res === "object" &&
64+
!!res &&
65+
"video" in res &&
66+
typeof res.video === "object" &&
67+
!!res.video &&
68+
"video_url" in res.video &&
69+
typeof res.video.video_url === "string" &&
70+
isUrl(res.video.video_url);
71+
if (!isValidOutput) {
72+
throw new InferenceOutputError("Expected { video: { video_url: string } }");
73+
}
74+
const urlResponse = await fetch((res as NovitaOutput).video.video_url);
5575
return await urlResponse.blob();
5676
} else {
5777
/// TODO: Replicate: handle the case where the generation request "times out" / is async (ie output is null)

0 commit comments

Comments
 (0)