diff --git a/src/components/models/code/WhisperBase64Code.astro b/src/components/models/code/WhisperBase64Code.astro new file mode 100644 index 000000000000000..35ecb38e69b5afb --- /dev/null +++ b/src/components/models/code/WhisperBase64Code.astro @@ -0,0 +1,46 @@ +--- +import { z } from "astro:schema"; +import { Code } from "@astrojs/starlight/components"; +import Details from "~/components/Details.astro"; +import Render from "~/components/Render.astro"; + +type Props = z.infer; + +const props = z.object({ + name: z.string(), +}); + +const { name } = props.parse(Astro.props); + +const worker = `import { Buffer } from 'node:buffer'; +export interface Env { + AI: Ai; +} +const URL = "https://pub-dbcf9f0bd3af47ca9d40971179ee62de.r2.dev/02f6edc0-1f7b-4272-bd17-f05335104725/audio.mp3"; +export default { + async fetch(request, env, ctx): Promise { + const mp3 = await fetch(URL); + if (!mp3.ok) { + return Response.json({ error: \`Failed to fetch MP3: \${mp3.status}\` }); + } + const mp3Buffer = await mp3.arrayBuffer(); + const base64 = Buffer.from(mp3Buffer, 'binary').toString("base64"); + try { + const res = await env.AI.run("${name}", { + "audio": base64 + }); + return Response.json(res); + } + catch (e) { + console.error(e); + return Response.json({ error: "An unexpected error occurred" }); + } + }, +} satisfies ExportedHandler + `; +--- + +
+ + +
diff --git a/src/pages/workers-ai/models/[name].astro b/src/pages/workers-ai/models/[name].astro index 38142cdf549e3b0..465bddbf50c60ee 100644 --- a/src/pages/workers-ai/models/[name].astro +++ b/src/pages/workers-ai/models/[name].astro @@ -22,6 +22,7 @@ import TranslationCode from "~/components/models/code/TranslationCode.astro"; import StableDiffusionV15Img2ImgCode from "~/components/models/code/StableDiffusion-v1-5-img2imgCode.astro"; import StableDiffusionV15InpaintingCode from "~/components/models/code/StableDiffusion-v1-5-inpaintingCode.astro"; import Flux1Schnell from "~/components/models/code/Flux-1-Schnell.astro"; +import WhisperBase64Code from "~/components/models/code/WhisperBase64Code.astro"; import { authorData } from "~/components/models/data"; @@ -88,6 +89,10 @@ if (model.name === "@cf/black-forest-labs/flux-1-schnell") { CodeExamples = Flux1Schnell; } +if (model.name === "@cf/openai/whisper-large-v3-turbo") { + CodeExamples = WhisperBase64Code; +} + const description = model.description; const terms = model.properties.find((x) => x.property_id === "terms");