Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/components/models/code/WhisperBase64Code.astro
Original file line number Diff line number Diff line change
@@ -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<typeof props>;

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<Response> {
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<Env>
`;
---

<Details header="Workers - TypeScript">
<Code code={worker} lang="ts" />
<Render file="nodejs-compat-howto" product="workers" />
</Details>
5 changes: 5 additions & 0 deletions src/pages/workers-ai/models/[name].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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");

Expand Down
Loading