Evaluating and Tuning Large Language Models for Interactive Frontend Generation

    This article explains why complex, single-file interactive web applications have become a hard benchmark for large language model capabilities, and how to evaluate and tune them reliably. It covers how to separate model-capability metrics from service-side engineering metrics, how to write explicit interaction and visual contracts in prompts, and how to avoid common failure modes such as drag coordinate jumps, hardcoded z-index, and visual degradation. It walks through two representative test cases—a desktop window manager and a real-time strategy mini-game—including a fixed-timestep game loop and hex-grid BFS pathfinding, and addresses regression problems during multi-turn iteration through requirement freezing, versioned rollbacks, and split validation. Readers will gain a reproducible, engineering-oriented approach to model selection and prompt optimization rather than relying on subjective impressions.

    1. Why “complex interactive frontends” are a hard test of model capability

    In model capability evaluation, static code completion tasks have long approached saturation: function-level completion, unit test generation, regex and SQL writing—most first-tier models now pass these in a single attempt. What actually separates them are tasks with high state complexity, immediate interactive feedback, and acceptance criteria that are visually obvious.

    Single-file, runnable web applications satisfy all three conditions at once:

    • State complexity: window stacking order, unit coordinates, resource values, and viewport offsets are all mutable state. The model must maintain a coherent data model rather than scattering DOM fragments.
    • Immediate verifiability: whether dragging follows the cursor, whether animations drop frames, and whether buttons feel materially textured are all apparent the moment you open the page—no test project needs to be set up.
    • Long-output consistency: generating thousands of lines of code in one shot requires variable naming, coordinate conventions, and rendering loops to stay self-consistent across the entire file, which puts extreme pressure on long-context utilization.

    For this reason, such tasks fundamentally test four capabilities: how well a model abstracts domain knowledge, how it infers intent behind implicit requirements, how it manages state across modules, and whether it can stay structurally consistent without collapsing across long outputs.

    2. Choosing the evaluation environment and eliminating confounding variables

    Similar capabilities are often also offered through online debugging workstations: paste a prompt, preview the rendered result directly, and append requirements across multiple turns. These environments lower the evaluation barrier, but they introduce a problem that is easy to overlook—server-side queuing and response latency.

    A common misjudgment is to attribute long waits, interrupted generation, or rate-limit retries to “degraded model capability.” When running capability evaluations, it is worth recording two categories of metrics separately:

    Metric category Observation items Attribution
    Capability metrics Requirement coverage, first-pass rate, visual fidelity Model
    Engineering metrics Time to first byte, total elapsed time, failure retry rate Service and network

    At the same time, run each case in a fresh session to avoid contamination from prior context, and repeat each case at least three times, drawing conclusions from the pass rate rather than a single run.

    3. Test Case 1: Fidelity of a desktop window system

    This class of task asks the model to recreate the window manager of a classic desktop operating system: dragging by the title bar, click-to-front, multiple stacked windows, and a transition animation with a perspective effect. The difficulty lies not in the amount of code but in faithfully reproducing materials and layering—translucent frosted glass, 1px highlight strokes, and soft outer shadows are exactly the details models tend to “simplify away.”

    There are three typical failure modes:

    1. Static appearance only: drag events are not bound, or coordinates lack offset compensation, causing the cursor to jump.
    2. Missing layer management: z-index is hardcoded, so a window does not come to the front when clicked.
    3. Visual degradation: solid-color backgrounds replace blur and transparency, sharply reducing the sense of interaction.

    The prompt should state the visual contract and boundary behavior explicitly instead of leaving it to the model’s discretion:

    1. 【Goal】A single-file, runnable web app that recreates a classic desktop window manager
    2. 【Interaction list】
    3. 1. Drag window by title bar: on mousedown, record the offset between the cursor
    4. and the window's top-left corner; on move, update coordinates by that offset.
    5. No cursor jumping.
    6. 2. Boundary clamping: at all times, at least the title bar stays within the viewport.
    7. 3. Layer management: on mousedown, raise the window's z-index to the global maximum;
    8. lower the brightness and shadow strength of inactive windows.
    9. 4. View switching: hold a designated key to trigger 3D perspective tiling;
    10. release it to return to the stacked layout.
    11. 【Visual constraints】
    12. - Window background uses semi-transparency + backdrop-filter blur, with a
    13. 1px semi-transparent white stroke.
    14. - Do not use solid-color backgrounds to replace the frosted-glass effect.
    15. 【Engineering constraints】
    16. - Vanilla HTML/CSS/JS only, no build step, double-click to run.
    17. - Keep state centralized in a single store object; event handlers only mutate
    18. state and never assemble the DOM directly.

    The key is item 4 together with the engineering constraints: writing “materials must not be degraded” as a hard constraint noticeably reduces visual simplification, while decoupling state from rendering prevents structural rot during later multi-turn iteration.

    4. Test Case 2: High-level abstraction in a real-time strategy mini-game

    Rework-style tasks built on a web-based strategy game operate at a clearly higher level of abstraction, because the original requirements often include features absent from the model’s training data and must be filled in through intent inference.

    4.1 Converting turn-based to real-time

    This checks whether the model truly understands the mechanics of real-time strategy: there is no turn button, both sides advance along the same timeline, and time is fair. A qualifying implementation needs a main loop with a fixed timestep:

    1. let last = performance.now();
    2. let accumulator = 0;
    3. let speed = 1; // 1x ~ 10x, controlled by the slider
    4. const STEP = 100; // base step size (milliseconds)
    5. function loop(now) {
    6. const dt = Math.min(now - last, 250); // clamp long frames to avoid a burst after backgrounding
    7. last = now;
    8. accumulator += dt * speed;
    9. while (accumulator >= STEP) {
    10. simulate(STEP); // advance at a fixed step so speed changes don't alter the logic result
    11. accumulator -= STEP;
    12. }
    13. render();
    14. requestAnimationFrame(loop);
    15. }
    16. requestAnimationFrame(loop);

    The point here is a fixed step size with speed affecting only how often it advances: if you multiply speed directly into the displacement, high speed will skip collision checks and break pathfinding continuity—an extremely common implementation flaw.

    4.2 Auto-research assistant

    This one is the most interesting: no such feature exists in the real game, so the model must infer a “checkable AI assistant system”—automatically investing in technology research when resources are sufficient. A qualifying implementation includes three elements: an on/off state, a resource-threshold check, and automatic enqueueing into the research queue. A failing implementation usually adds only a UI toggle with no state machine driving it.

    4.3 Automatic unit targeting

    “All units automatically seek out opponents” involves grid pathfinding. Hexagonal adjacency and axial coordinate conversion are the foundation, and pathfinding can use breadth-first search to guarantee correctness:

    1. const HEX_SIZE = 32;
    2. function hexToPixel(q, r) {
    3. return {
    4. x: HEX_SIZE * Math.sqrt(3) * (q + r / 2),
    5. y: HEX_SIZE * 1.5 * r
    6. };
    7. }
    8. function nextStep(start, goals, passable) {
    9. const prev = new Map([[key(start), null]]);
    10. const queue = [start];
    11. while (queue.length) {
    12. const cur = queue.shift();
    13. if (goals.has(key(cur))) { // hit any target
    14. let p = cur;
    15. while (prev.get(key(p)) && prev.get(key(p)) !== start) p = prev.get(key(p));
    16. return p; // return the first step, hand off to movement logic
    17. }
    18. for (const nb of neighborsHex(cur)) {
    19. if (!passable(nb) || prev.has(key(nb))) continue;
    20. prev.set(key(nb), cur);
    21. queue.push(nb);
    22. }
    23. }
    24. return null;
    25. }

    This requirement is coupled with the “hexagonal grid” detail requirement: if the model implements pathfinding on a square grid first, switching to hexagons later forces synchronized changes to coordinate conversion, the adjacency function, and drawing offsets. Passing on the first attempt requires declaring the grid type in the prompt up front.

    4.4 Control and presentation details

    The speed slider (1x–10x), the hexagonal grid, arrow keys to switch the view, and using emoji or encoded icons for objects such as cities—these four items are low-abstraction but high-coverage acceptance points, a sieve for judging whether the model “missed requirements.” It is best to score them item by item rather than assign a single overall impression score.

    5. Regression problems in multi-turn iteration and how to handle them

    A counterintuitive phenomenon often appears in practice: after appending requirements over multiple turns, quality can end up lower than in the first round. There are three main causes:

    • Context drift: early conventions are overwritten by later instructions; the coordinate system is unified to a square grid, and the visual spec regresses to solid color.
    • Attention dilution: once the prompt swells to thousands of tokens, the weight of early constraints drops.
    • Cascading breakage from incremental edits: rewriting the main loop just to add a slider causes the existing speed semantics to break.

    Corresponding strategies:

    1. Freeze requirements + version control: allow only new requirements each round, never modification of accepted items, and restate a concise acceptance checklist at the tail of the prompt.
    2. Rollback over patching: if a round’s changes introduce a structural regression, opening a clean session and regenerating everything in one shot with the full prompt usually beats continuing to patch.
    3. Split validation: test “functional correctness” and “visual fidelity” separately so that problems in one dimension do not mask conclusions about the other.

    6. Implementation recommendations

    When integrating this kind of generation capability into a production system, it is worth combining general cloud capabilities rather than relying on a single interface:

    • Model services: perform multi-model routing and fallback through a unified model access layer, making horizontal evaluation and cost optimization easier.
    • Container platforms: host rendering previews and code-execution sandboxes for resource isolation and timeout circuit-breaking.
    • Object storage: store generated artifacts and snapshots to support version rollback and comparison.
    • Logging services and monitoring/alerting: collect time to first byte, generation success rate, and retry rate, turning evaluation metrics into sustainable online indicators.

    On Baidu AI Cloud, these capabilities can be assembled from general-purpose components such as model services, containerized sandboxes, and logging and monitoring, forming a closed-loop evaluation pipeline of “question bank → automated execution → metric collection → regression comparison.”

    7. Summary

    Complex interactive frontend tasks are effective because they compress four capabilities—domain understanding, intent inference, state management, and long-output self-consistency—into a single carrier that can be verified by eye. The core principles when evaluating are: attribute capability and engineering metrics separately, replace single-run impressions with repeated experiments, turn implicit contracts into explicit constraints, and hold the two bottom lines of requirement freezing and version rollback across multi-turn iteration. Do these, and model selection and prompt optimization stop depending on subjective feeling and become a reproducible engineering practice.