返回提示库

代码生成

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.

参考来源