@@ -20,7 +20,13 @@ interface ReplicateOutput {
20
20
output : string ;
21
21
}
22
22
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 [ ] ;
24
30
25
31
export async function textToVideo ( args : TextToVideoArgs , options ?: Options ) : Promise < TextToVideoOutput > {
26
32
if ( ! args . provider || ! typedInclude ( SUPPORTED_PROVIDERS , args . provider ) ) {
@@ -30,14 +36,13 @@ export async function textToVideo(args: TextToVideoArgs, options?: Options): Pro
30
36
}
31
37
32
38
const payload =
33
- args . provider === "fal-ai" || args . provider === "replicate"
39
+ args . provider === "fal-ai" || args . provider === "replicate" || args . provider === "novita"
34
40
? { ...omit ( args , [ "inputs" , "parameters" ] ) , ...args . parameters , prompt : args . inputs }
35
41
: args ;
36
- const res = await request < FalAiOutput | ReplicateOutput > ( payload , {
42
+ const res = await request < FalAiOutput | ReplicateOutput | NovitaOutput > ( payload , {
37
43
...options ,
38
44
task : "text-to-video" ,
39
45
} ) ;
40
-
41
46
if ( args . provider === "fal-ai" ) {
42
47
const isValidOutput =
43
48
typeof res === "object" &&
@@ -51,7 +56,22 @@ export async function textToVideo(args: TextToVideoArgs, options?: Options): Pro
51
56
if ( ! isValidOutput ) {
52
57
throw new InferenceOutputError ( "Expected { video: { url: string } }" ) ;
53
58
}
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 ) ;
55
75
return await urlResponse . blob ( ) ;
56
76
} else {
57
77
/// TODO: Replicate: handle the case where the generation request "times out" / is async (ie output is null)
0 commit comments