|
"use server" |
|
|
|
import { parseClap } from "@/lib/clap/parseClap" |
|
import { ClapProject } from "@/lib/clap/types" |
|
|
|
import { aitubeApiUrl } from "../config" |
|
|
|
export async function generateClap({ |
|
prompt = "", |
|
}: { |
|
prompt: string |
|
}): Promise<ClapProject> { |
|
if (!prompt) { throw new Error(`please provide a prompt`) } |
|
|
|
|
|
const height = 1024 |
|
const width = 512 |
|
|
|
|
|
|
|
|
|
const res = await fetch(`${aitubeApiUrl}generate/story`, { |
|
method: "POST", |
|
headers: { |
|
"Content-Type": "application/json", |
|
|
|
|
|
}, |
|
body: JSON.stringify({ |
|
prompt, |
|
width, |
|
height |
|
}), |
|
cache: "no-store", |
|
|
|
|
|
}) |
|
|
|
const blob = await res.blob() |
|
|
|
const clap = await parseClap(blob) |
|
|
|
return clap |
|
} |