About
A prompt playground with a model picker, temperature and max-token sliders, and live streaming output. Plug in any model through one onRun stream. Includes stop, copy, clear and run stats.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds AI Prompt Playground to your project and fits it to your theme.
Code
How AI Prompt Playground is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
// This is a file with a demo for your component
// That's what users will see in the preview
// Create new files in this directory to add more demos
"use client";
import * as React from "react";
import { Component, type PlaygroundModel, type RunParams } from "@/components/ui/ai-prompt-playground";
const MODELS: PlaygroundModel[] = [
{ id: "swift", name: "Swift 1", description: "Fast and light. Good for short answers." },
{ id: "balanced", name: "Balanced 2", description: "The everyday model. A good mix of speed and quality." },
{ id: "deep", name: "Deep 3", description: "Slower, but better at long and careful answers." },
];
const EXAMPLES = ["Explain how a hash map works", "Write a friendly product update email", "Give me 5 names for a note-taking app"];
// A pretend model. It streams a few words at a time, the way a real API would.
const ANSWER =
"Here is a short answer. A good result starts with a clear goal, so state who it is for and what you want them to do. " +
"Keep sentences short, give one concrete example, and end with a single next step. " +
"You can ask for a different tone, a shorter version, or more detail at any time, and the model will adjust.";
async function* fakeStream({ prompt, modelId, temperature, maxTokens }: RunParams, signal: AbortSignal) {
// The first words tell you the settings arrived
const intro = "[" + modelId + " · temp " + temperature + "] Re: “" + prompt.slice(0, 40).trim() + (prompt.length > 40 ? "…" : "") + "”\n\n";
const words = (intro + ANSWER).split(" ");
let sent = 0;
for (const word of words) {
if (signal.aborted) throw new DOMException("Aborted", "AbortError");
await new Promise((resolve) => setTimeout(resolve, 45));
// Stop when the token budget is used up (about 1.3 tokens per word)
sent += 1.3;
if (sent > maxTokens) return;
yield word + " ";
}
}
export default function DemoOne() {
return (
<div className="flex min-h-[640px] w-full items-center justify-center bg-background px-4 py-10">
<Component
title="Prompt playground"
models={MODELS}
defaultModelId="balanced"
defaultPrompt={EXAMPLES[0]}
examplePrompts={EXAMPLES}
onRun={fakeStream}
/>
</div>
);
}
















