返回提示庫

代码生成

A code generation prompt for creating implementation-ready code with constraints, interfaces, acceptance criteria, and tests.

審校時間: 2026-03-18

Use this when you need the model to generate new code from a specification and you want fewer vague or toy outputs.

Prompt 模板

You are building production-ready {language} code.

Build:
{feature_request}

Project context:
- Runtime/framework: {runtime}
- Existing interfaces or contracts: {interfaces}
- Constraints: {constraints}
- Input/output expectations: {io_requirements}
- Acceptance criteria: {acceptance_criteria}

Return exactly:
1. A short implementation plan.
2. The final code in fenced blocks.
3. Minimal usage example.
4. Tests or validation cases.

正式使用前,請先替換模板變數並補充你的限制條件。

適用場景

  • Generating a reusable utility or API route
  • Scaffolding a feature with strict constraints
  • Building a UI component from explicit requirements

期望輸出

  • Implementation plan
  • Production-focused code
  • Usage example
  • Validation or tests

可替換變數

language

Primary language

Example: TypeScript

feature_request

What should be built

Example: A paginated search helper for server-side routes

runtime

Framework and runtime

Example: Next.js route handler on Node

interfaces

Existing contracts or shapes

Example: SearchParams, SearchResponse

constraints

Hard implementation limits

Example: No external packages; must support abort signals

io_requirements

Input and output behavior

Example: Return stable JSON with pageInfo and items

acceptance_criteria

Definition of done

Example: Handles empty queries, bad pages, and server errors cleanly

優化建議

  • Give the model your existing types and interfaces instead of describing them loosely.
  • State non-goals to prevent unnecessary abstractions.
  • Ask for the smallest version that still meets your acceptance criteria.

示例用法

Generate a server-safe Open Graph metadata helper for a multilingual Next.js site.

預期效果

The model returns a focused implementation, a usage snippet, and the scenarios you should verify.

參考來源