Testing New LLMs: Model Selection and Prompt Engineering for Frontend Code Generation

    This article explores practical strategies for selecting LLMs and tuning reasoning effort for frontend code generation tasks, such as complex SVG creation. By comparing lightweight, previous-generation flagship, and new-generation flagship models, it provides a decision framework for matching model capabilities with task complexity. It also shares structured prompt engineering techniques to improve first-pass success rates and reduce overall token consumption.

    Testing New LLMs: Model Selection and Prompt Engineering for Frontend Code Generation

    1. Background: Why Model Version Differences Matter

    In daily development, an increasing number of teams are utilizing Large Language Models (LLMs) to generate frontend code, draw data visualization charts, and produce vector graphics (SVG). These tasks share a common characteristic: they demand extremely high structural integrity and detail fidelity. If a single closing tag is missing or a coordinate is wrong in a piece of SVG code, the rendered result will be completely distorted.

    In practice, developers generally observe a phenomenon: handing the same prompt to a lightweight model and a flagship model yields vastly different results. Lightweight models may get “stuck” mid-way or output truncated content. Furthermore, there are noticeable differences in stability and token efficiency between the new and old versions of flagship models. This article uses the high-pressure task of “generating complex SVG graphics with specified dimensions (e.g., 1200×1200)” as an example to systematically outline practical methods for model selection, reasoning effort adjustment, and prompt engineering.

    2. Observations: Three Typical Performance Profiles

    2.1 Lightweight Models: Vulnerable Under High Complexity

    In conversational interfaces and CLI coding assistants, lightweight models offer fast response times and low costs, making them suitable for daily Q&A and simple code completion. However, once multiple constraints are stacked in the prompt—such as “dimensions must be 1200×1200, include gradients, graphic elements must not be less than N, and maintain visual hierarchy”—lightweight models frequently exhibit the following issues:

    • Mid-generation truncation, failing to produce complete, runnable code;
    • Omitting key constraints, such as ignoring size limits;
    • “Losing” context as it gets longer, leading to inconsistent logic between the beginning and end.

    Conclusion: Lightweight models offer the best ROI for simple tasks; do not rely on them for complex tasks.

    2.2 Previous Flagship Models: Capable but Lacks Long-Task Stability

    Previous-generation flagship models are significantly stronger at understanding complex instructions and can correctly parse multi-constraint conditions. However, in scenarios requiring extremely long outputs (such as generating hundreds of lines of structured SVG code), their performance degrades as the output length increases:

    • Detail features begin to fade in the middle and late stages of generation;
    • To maintain overall structure, local precision is sacrificed;
    • Token consumption is relatively high, and the same task requires more rounds of correction.

    2.3 New Flagship Models: Dual Improvement in Stability and Efficiency

    Under the same high-pressure test (fixed dimensions + multiple constraints + long output), the advantages of the new-generation flagship models are primarily reflected in three areas:

    1. Strong feature retention capability: Key constraints are maintained from start to finish, with dimensions, color schemes, and structural hierarchy staying on track;
    2. No collapse in long output: Structural integrity is maintained even when the code volume is large, reducing the need for manual patching;
    3. Lower token consumption: For the same task, the new version often achieves a higher first-pass success rate, resulting in lower total consumption. This is often overlooked—a “higher unit price” for a model does not equate to a “higher total task cost.”

    3. Model Selection Decision Framework

    You can quickly make a selection using the following decision path:

    1. Task Complexity Assessment
    2. ├── Simple Q&A / Short code snippets → Lightweight model, low effort
    3. ├── Standard business code / Single-file features → Mid-tier model, medium effort
    4. └── Multi-constraint / Long output / High precision (SVG, complex frontend pages, architecture design)
    5. → Flagship model (prioritize new versions), high effort

    A few supplementary principles:

    • Constraint count is the watershed: If constraint conditions exceed 3–4, it is recommended to go directly to a flagship model;
    • Output length dictates risk: When the expected output exceeds a few hundred lines of code, the model’s long-term stability is more important than its short-term intelligence;
    • Calculate the total cost of iterations: A cheap model that requires three extra rounds of corrections might be more expensive than an expensive model that passes on the first try.

    4. How to Tune Effort (Reasoning Effort)

    Reasoning effort is essentially a trade-off between “thinking depth” and “response speed/cost”:

    • Low effort: Suitable for clear, pattern-based tasks, such as format conversion or simple completion. The model does not need long-chain thinking here.
    • Medium effort: Suitable for standard coding tasks that require some solution trade-offs but do not involve global architecture.
    • High effort: Suitable for tasks with overlapping multiple constraints that require trade-offs, such as “requiring precise dimensions, rich visual hierarchy, and maintainable code.” Under high effort, the model performs more internal solution comparisons internally, resulting in noticeably higher first-answer quality.

    A practical insight: Effort should match the model tier. Applying the highest effort to a lightweight model yields limited returns; applying low effort to a flagship model on a complex task wastes its capabilities.

    5. Prompt Engineering for Complex Tasks

    For high-precision tasks like SVG generation, the following structured prompt template is recommended:

    1. Role: Senior Frontend Engineer
    2. Task: Generate a piece of SVG code
    3. Hard Constraints:
    4. 1. Canvas size 1200x1200, no deviation allowed
    5. 2. viewBox must match the dimensions
    6. 3. Output must be complete and directly renderable, no ellipsis or pseudocode allowed
    7. Design Requirements:
    8. 1. Harmonious color matching between primary and secondary colors
    9. 2. Clear element layering, use <g> for grouping and add comments
    10. 3. Output the code completely in one go, do not split into segments
    11. Acceptance Criteria: Self-check all hard constraints one by one to ensure they are met

    Key techniques:

    1. Prioritize and number “non-negotiable constraints” so the model does not forget them when generating long code;
    2. Explicitly demand “one-shot complete output” to avoid context breakage caused by segmented output;
    3. Attach self-check instructions, asking the model to confirm each constraint at the end of the output;
    4. Avoid piling up vague adjectives. Instead of “grand and beautiful,” use verifiable descriptions like “primary color #1E3A8A, whitespace ratio 20%.”

    6. Conclusion

    The core of model selection is not “the newer, the better” or “the more expensive, the better,” but rather the matching of task complexity, model capability, and reasoning effort. Use lightweight models for daily tasks and new flagship models for complex, long-output tasks with multiple constraints. Scale the effort up or down with task difficulty. Through structured, numbered, and verifiable constraint descriptions, prompt engineering truly translates the stability advantage of the models into first-pass success rates. Choosing the right combination is the optimal solution for both efficiency and cost.