themeocean

AI Prompt Playground

AI chats

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>
  );
}

Dependencies

More by themeocean

View all
  • Interactive Tech Stack Bento Grid with Hover Effects

    Interactive Tech Stack Bento Grid with Hover Effects

    780
  • Floating Glassmorphic Navbar with Morphing Pill Indicator

    Floating Glassmorphic Navbar with Morphing Pill Indicator

    87
  • Mac-Style Floating Dock

    Mac-Style Floating Dock

    79
  • Nexus 3D Animated Login - Futuristic Authentication UI

    Nexus 3D Animated Login - Futuristic Authentication UI

    72
  • Animated 3D Perspective Hero with Floating Glass Layers

    Animated 3D Perspective Hero with Floating Glass Layers

    51
  • Interactive AI Agent Workflow Node Card

    Interactive AI Agent Workflow Node Card

    38
  • Interactive LLM Token & Context Window Visualizer

    Interactive LLM Token & Context Window Visualizer

    31
  • Interactive AI Voice Assistant Audio Visualizer

    Interactive AI Voice Assistant Audio Visualizer

    24

More in AI chats

View all
  • Agent Chat

    Agent Chat

    21
  • AI Suggestions

    AI Suggestions

    27
  • AI Actions

    AI Actions

    372
  • Aquarium Prompt

    Aquarium Prompt

    223
  • Message Parts

    Message Parts

    11
  • AI SaaS Workflow Hero

    AI SaaS Workflow Hero

    37
  • AI Chat Composer

    AI Chat Composer

    22
  • Tool Memory

    Tool Memory

    10