Skip to content

Commit 8330bbb

Browse files
feat: Adds code example for Melotts (#22567)
* feat: Adds code example for Melotts * Update src/components/models/code/MelottsCode.astro Co-authored-by: Michael Hart <[email protected]> --------- Co-authored-by: Michael Hart <[email protected]>
1 parent 66c90b6 commit 8330bbb

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { Code } from "@astrojs/starlight/components";
4+
import Details from "~/components/Details.astro";
5+
6+
type Props = z.infer<typeof props>;
7+
8+
const props = z.object({
9+
name: z.string(),
10+
});
11+
12+
const { name } = props.parse(Astro.props);
13+
14+
const worker = `
15+
export interface Env {
16+
AI: Ai;
17+
}
18+
19+
export default {
20+
async fetch(request, env): Promise<Response> {
21+
const { audio } = await env.AI.run('${name}', {
22+
prompt: 'Hello world',
23+
lang: 'en',
24+
});
25+
// Returns the base64 encoded MP3 audio
26+
return Response.json({ audio });
27+
},
28+
} satisfies ExportedHandler<Env>;`;
29+
---
30+
31+
<Details header="Workers - TypeScript">
32+
<Code code={worker} lang="ts" />
33+
</Details>

src/pages/workers-ai/models/[name].astro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import StableDiffusionV15Img2ImgCode from "~/components/models/code/StableDiffus
2323
import StableDiffusionV15InpaintingCode from "~/components/models/code/StableDiffusion-v1-5-inpaintingCode.astro";
2424
import Flux1Schnell from "~/components/models/code/Flux-1-Schnell.astro";
2525
import WhisperBase64Code from "~/components/models/code/WhisperBase64Code.astro";
26+
import MelottsCode from "~/components/models/code/MelottsCode.astro";
2627
import LlamaGuard from "~/components/models/code/LlamaGuard.astro";
2728
import BgeRerankerBase from "~/components/models/code/Bge-Reranker-Base.astro";
2829
@@ -95,6 +96,10 @@ if (model.name === "@cf/openai/whisper-large-v3-turbo") {
9596
CodeExamples = WhisperBase64Code;
9697
}
9798
99+
if (model.name === "@cf/myshell-ai/melotts") {
100+
CodeExamples = MelottsCode;
101+
}
102+
98103
if (model.name === "@cf/meta/llama-guard-3-8b") {
99104
CodeExamples = LlamaGuard;
100105
}
@@ -251,4 +256,4 @@ const starlightPageProps = {
251256
<Code code={JSON.stringify(model.schema.output, null, 4)} lang="json" />
252257
</TabItem>
253258
</Tabs>
254-
</StarlightPage>
259+
</StarlightPage>

0 commit comments

Comments
 (0)