-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e36194d
commit bf0700f
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/app/src/app/api/resolve/providers/hotshot/createHotshotVideo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
HotshotVideoGenerationParams, | ||
HotshotVideoGenerationResponse, | ||
} from './types' | ||
|
||
/** | ||
* Asynchronous function to initiate video generation using the Hotshot API. | ||
* @param apiKey - The API key for authentication. | ||
* @param params - The parameters for video generation. | ||
* @returns A promise that resolves to the video generation response. | ||
*/ | ||
export async function createHotshotVideo( | ||
apiKey: string, | ||
params: HotshotVideoGenerationParams | ||
): Promise<HotshotVideoGenerationResponse> { | ||
const baseUrl = 'https://hotshot.co' | ||
const headers = { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
|
||
// I think right now it's using cookies | ||
// 'X-API-Key': apiKey, | ||
} | ||
|
||
try { | ||
const response = await fetch(`${baseUrl}/api/v1/text-to-video/generate`, { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify(params), | ||
}) | ||
|
||
// note: at this stage normally we should connect to the queue using websockets | ||
// however since we are an API context and Hotshot is slow to generate, | ||
// a simply polling is probably more than enough | ||
// eg initial wait time of 20 seconds + check every 5 sec | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const data: HotshotVideoGenerationResponse = await response.json() | ||
return data | ||
} catch (error) { | ||
console.error('Error in video generation:', error) | ||
throw error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/app/src/app/api/resolve/providers/hotshot/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Represents the parameters for the Hotshot video generation request. | ||
*/ | ||
export type HotshotVideoGenerationParams = { | ||
prompt: string | ||
prompt_options: string // " --generation-type generate" | ||
|
||
// I think this is just a randomly generated UUID | ||
request_id: string // eg. "6bf37b2d-576b-4ae0-93d4-9e7980fa3ce3" | ||
|
||
generation_type: string // "generate" | ||
|
||
files: Array<any> // for future use? | ||
} | ||
|
||
/** | ||
* Represents the response from the Hotshot video generation request. | ||
*/ | ||
export type HotshotVideoGenerationResponse = { | ||
// will be something like "https://dvfx9cgvtgnyd.cloudfront.net", | ||
cdnHost: string | ||
|
||
// will be something like "6bf37b2d-576b-4ae0-93d4-9e7980fa3ce3", | ||
request_id: string | ||
|
||
responses: Array<{ | ||
message: string // "submitted to ['eC4XDlU_d72nqFG5AAAn']" | ||
}> | ||
} |