File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ import { z } from " astro:schema" ;
3+ import { Code } from " @astrojs/starlight/components" ;
4+ import Details from " ~/components/Details.astro" ;
5+ import Render from " ~/components/Render.astro" ;
6+
7+ type Props = z .infer <typeof props >;
8+
9+ const props = z .object ({
10+ name: z .string (),
11+ });
12+
13+ const { name } = props .parse (Astro .props );
14+
15+ const worker = ` import { Buffer } from 'node:buffer';
16+ export interface Env {
17+ AI: Ai;
18+ }
19+ const URL = "https://pub-dbcf9f0bd3af47ca9d40971179ee62de.r2.dev/02f6edc0-1f7b-4272-bd17-f05335104725/audio.mp3";
20+ export default {
21+ async fetch(request, env, ctx): Promise<Response> {
22+ const mp3 = await fetch(URL);
23+ if (!mp3.ok) {
24+ return Response.json({ error: \` Failed to fetch MP3: \$ {mp3.status}\` });
25+ }
26+ const mp3Buffer = await mp3.arrayBuffer();
27+ const base64 = Buffer.from(mp3Buffer, 'binary').toString("base64");
28+ try {
29+ const res = await env.AI.run("${name }", {
30+ "audio": base64
31+ });
32+ return Response.json(res);
33+ }
34+ catch (e) {
35+ console.error(e);
36+ return Response.json({ error: "An unexpected error occurred" });
37+ }
38+ },
39+ } satisfies ExportedHandler<Env>
40+ ` ;
41+ ---
42+
43+ <Details header =" Workers - TypeScript" >
44+ <Code code ={ worker } lang =" ts" />
45+ <Render file =" nodejs-compat-howto" product =" workers" />
46+ </Details >
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import TranslationCode from "~/components/models/code/TranslationCode.astro";
2222import StableDiffusionV15Img2ImgCode from " ~/components/models/code/StableDiffusion-v1-5-img2imgCode.astro" ;
2323import StableDiffusionV15InpaintingCode from " ~/components/models/code/StableDiffusion-v1-5-inpaintingCode.astro" ;
2424import Flux1Schnell from " ~/components/models/code/Flux-1-Schnell.astro" ;
25+ import WhisperBase64Code from " ~/components/models/code/WhisperBase64Code.astro" ;
2526
2627import { authorData } from " ~/components/models/data" ;
2728
@@ -88,6 +89,10 @@ if (model.name === "@cf/black-forest-labs/flux-1-schnell") {
8889 CodeExamples = Flux1Schnell ;
8990}
9091
92+ if (model .name === " @cf/openai/whisper-large-v3-turbo" ) {
93+ CodeExamples = WhisperBase64Code ;
94+ }
95+
9196const description = model .description ;
9297const terms = model .properties .find ((x ) => x .property_id === " terms" );
9398
You can’t perform that action at this time.
0 commit comments