Skip to content

Commit

Permalink
investigating hotshot
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke-hf committed Aug 22, 2024
1 parent e36194d commit bf0700f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
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
}
}
2 changes: 2 additions & 0 deletions packages/app/src/app/api/resolve/providers/hotshot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export async function resolveSegment(
// TODO: implement the Hotshot API
// (current status: waiting to hear back)

// createHotshotVideo(...)

throw new Error(
`Clapper doesn't support ${request.segment.category} generation for provider "Hotshot". Please open a pull request with (working code) to solve this!`
)
Expand Down
29 changes: 29 additions & 0 deletions packages/app/src/app/api/resolve/providers/hotshot/types.ts
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']"
}>
}

0 comments on commit bf0700f

Please sign in to comment.