StealThis .dev

Prompt Playground

A developer-facing prompt playground with system and user editors, model and sampling controls, a live token meter that estimates cost, and a simulated streamed completion.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

The Prompt Playground is a self-contained workbench for iterating on LLM prompts. Two editors hold the system and user messages, while a parameter rail exposes a model selector, temperature and top-p sliders, and a max-tokens control. A live meter tallies characters and estimated tokens across both prompts and multiplies them by the selected model’s per-million input price to project a request cost in real time. A {{variable}} panel lets you define template values that are interpolated into the compiled prompt before sending.

Pressing Run compiles the messages, then produces a simulated completion that streams in token by token so you can feel the latency of a real request. The streaming loop is driven by requestAnimationFrame for smooth, frame-aligned appends, and can be stopped mid-flight. Everything updates optimistically: dragging a slider re-labels its value, editing a prompt re-counts tokens, and defining a variable immediately re-resolves the preview.

The component demonstrates the requestAnimationFrame scheduling API for cancellable, jank-free streaming, alongside Intl.NumberFormat for locale-aware cost formatting and a lightweight {{template}} interpolation pass over textarea input.