Skip to content

feat: Adds code example for Melotts #22567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2025
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
33 changes: 33 additions & 0 deletions src/components/models/code/MelottsCode.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
import { z } from "astro:schema";
import { Code } from "@astrojs/starlight/components";
import Details from "~/components/Details.astro";

type Props = z.infer<typeof props>;

const props = z.object({
name: z.string(),
});

const { name } = props.parse(Astro.props);

const worker = `
export interface Env {
AI: Ai;
}

export default {
async fetch(request, env): Promise<Response> {
const { audio } = await env.AI.run('${name}', {
prompt: 'Hello world',
lang: 'en',
});
// Returns the base64 encoded MP3 audio
return Response.json({ audio });
},
} satisfies ExportedHandler<Env>;`;
---

<Details header="Workers - TypeScript">
<Code code={worker} lang="ts" />
</Details>
7 changes: 6 additions & 1 deletion src/pages/workers-ai/models/[name].astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import StableDiffusionV15Img2ImgCode from "~/components/models/code/StableDiffus
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 MelottsCode from "~/components/models/code/MelottsCode.astro";
import LlamaGuard from "~/components/models/code/LlamaGuard.astro";
import BgeRerankerBase from "~/components/models/code/Bge-Reranker-Base.astro";

Expand Down Expand Up @@ -95,6 +96,10 @@ if (model.name === "@cf/openai/whisper-large-v3-turbo") {
CodeExamples = WhisperBase64Code;
}

if (model.name === "@cf/myshell-ai/melotts") {
CodeExamples = MelottsCode;
}

if (model.name === "@cf/meta/llama-guard-3-8b") {
CodeExamples = LlamaGuard;
}
Expand Down Expand Up @@ -251,4 +256,4 @@ const starlightPageProps = {
<Code code={JSON.stringify(model.schema.output, null, 4)} lang="json" />
</TabItem>
</Tabs>
</StarlightPage>
</StarlightPage>
Loading