Logo for AiToolGo

Prompt Engineering from Zero to One: Techniques and Practice for Building High-Quality AI Prompts

In-depth discussion
Easy to understand
 0
 0
 1
本文系统介绍提示工程(Prompt Engineering)的基本概念与六大原则,涵盖提示词分类(3D、文本、音乐、视频、图像生成),并介绍CRISPE、CO-STAR等提示词框架及LangGPT结构化提示词方法论,包括模块设计、思维链构建与语义一致性技巧。文章通过“strawberry字母计数”和剧本创作、公文写作助手等实战案例,展示从普通提示到结构化提示的效果提升,并提供自动化生成LangGPT提示词的模板。
  • main points
  • unique insights
  • practical applications
  • key topics
  • key insights
  • learning outcomes
  • • main points

    • 1
      结构清晰,从概念入门到原则、框架、方法论再到实战逐层递进
    • 2
      提供了可直接套用的提示词框架与模板(CRISPE、CO-STAR、LangGPT)
    • 3
      通过前后对比的实战案例直观展示结构化提示词的效果差异
  • • unique insights

    • 1
      将LangGPT的模块化设计类比面向对象编程,提出基于角色的双层结构(模块与内部元素)
    • 2
      强调提示词各部分之间的格式语义一致性与内容语义一致性,指出标识符功能混用会干扰模型对层级的识别
  • • practical applications

    • 读者可以学习结构化提示词的写作方法,并直接使用文中的模板与实战案例快速改进与AI交互的效果,适用于写作、角色扮演、商业文案等多种场景。
  • • key topics

    • 1
      提示工程基本概念与六大原则
    • 2
      提示词全景分类(文本、图像、视频、音乐、3D生成)
    • 3
      CRISPE、CO-STAR与LangGPT结构化提示词框架
  • • key insights

    • 1
      结合LangGPT模块化思路与思维链(CoT)构建完整提示词的方法
    • 2
      通过“strawberry字母计数”等实例直观对比普通与优化提示词效果
    • 3
      提供自动化生成LangGPT提示词的元提示模板
  • • learning outcomes

    • 1
      掌握提示工程的基本概念与六大设计原则
    • 2
      学会使用CRISPE、CO-STAR及LangGPT等框架构建结构化提示词
    • 3
      能够基于模板设计剧本创作、公文写作等场景的专业提示词
examples
tutorials
code samples
visuals
fundamentals
advanced content
practical tips
best practices

“ 1. Understanding Prompts and Prompt Engineering

A prompt is the instruction given to a generative AI model, such as a large language model. It works like a task order: usually a short piece of text or a question that tells the model what to do. Prompt Engineering is the discipline of designing and refining these inputs so that the model returns more accurate, useful, and well-targeted outputs. When working with advanced models like ChatGPT, how you phrase your input largely determines the quality of the response. Prompt engineering rests on three key aspects. First, prompt design: choosing the right vocabulary and sentence structure to express your needs. For example, requesting an academic paper might include keywords such as 'academic writing', 'cite sources', and 'rigorous logic', while an image prompt might specify scene description, style (e.g., 'photorealistic' or 'cartoon'), and color palette. Second, prompt optimization: iterating through trials to find the best combination of keywords. Order and emphasis matter, since some terms weigh more heavily on the output. Third, context awareness: in multi-turn conversations, new prompts should reference earlier exchanges so that the responses remain coherent and logically consistent, much like a natural human conversation.

“ 2. Six Core Principles of Prompt Engineering

Principle 1 - Be clear about instructions. Vague prompts confuse models. Instead of asking for 'environmental content', specify 'detail the environmental measures currently implemented in cities and their measured effects'. Principle 2 - Provide reference material. Supplying samples helps the model match the desired type and style. To imitate Hemingway's voice, include a passage from his work as a reference. Principle 3 - Break complex tasks into subtasks. For a large project such as designing a virtual city, handle building design first, then character setup, then environment layout, rather than requesting everything at once. Principle 4 - Give the model time to think (Chain-of-Thought). Ask the model to reason step by step before giving a final answer. For a geometry proof, request an analysis of the given conditions and applicable theorems before the conclusion. Adding 'think step by step' often improves accuracy. Principle 5 - Use external tools. Connect models to data analysis software, literature search tools, or code execution environments to obtain up-to-date information and verify results. Principle 6 - Test variations systematically. Design different prompt versions (e.g., emphasizing product features, user experience, or competitor comparison for a marketing copy), test them, and measure which yields the best results.

“ 3. A Panorama of Prompt Categories

Prompts can be grouped by output modality: - 3D Generation: 3D models, scene construction, character modeling, object generation, 3D assets, and environment design. Tools include GET3D and Tripo3D. - Text Generation: copywriting, content creation, code generation, translation, academic writing, data analysis, creative writing, and copy optimization. Tools include ChatGPT and Claude. - Music and Sound Generation: background music, sound effects, soundtrack composition, arrangement, voice cloning, and sound design. Tools include Suno. - Video Generation: video editing, special effects, AI presenters, digital humans, educational and entertainment videos, and scene generation. Tools include Runway, Pika Labs, and similar platforms. - Image Generation: artistic creation, concept design, commercial illustration, image generation, image editing, and style transfer. Tools include Midjourney, DALL-E, and Stable Diffusion/Flux.

“ 4. Popular Prompt Frameworks: CRISPE and CO-STAR

CRISPE Framework: - Capacity and Role: assign the AI a role, such as expert or assistant. - Insight: provide background and context so the model understands the situation. - Statement: state the specific task clearly. - Personality: define the response style, such as humorous or serious. - Experiment: request several alternative answers for comparison. Example: 'Act as a software development expert and professional blogger in machine learning frameworks. The audience is technical professionals interested in recent advances. Provide a comprehensive overview of popular frameworks, covering strengths and weaknesses, and include real-world case studies.' CO-STAR Framework: - Context: the background of the task. - Objective: the specific task the model should perform. - Style: the writing style to adopt. - Tone: the emotional tendency of the reply. - Audience: who the response is intended for. - Response: the required output format. Both frameworks give prompts a predictable structure that is easy to reuse and adapt.

“ 5. Structured Prompting with LangGPT

LangGPT is a tool and methodology for writing high-quality prompts through structured, modular design. Borrowing ideas from object-oriented programming, it uses a role-based two-level structure. A complete prompt consists of modules (aspects the LLM should address, such as background, suggestions, or constraints) and internal elements (the specific requirements within a module, either value-type or method-type). A typical LangGPT template follows a reasoning chain: define the Role, then the Profile, Skills, Rules, Workflow, and finally Initialization. This sequence guides the model logically from identity to behavior. The following base template illustrates the structure: # Role: role name (global scope) ## Profile: author, version, language, and a brief description (paragraph scope) ### Skill: list of abilities ## Rules: behavioral rules ## Workflow: how to interact with the user ## Initialization: greeting and behavior setup Module selection depends on the scenario. For example, writing tasks typically use Profession, Constraints, Goal, Initialization, Example, Workflow, Skills, Background knowledge, Style, and Output, while role-play omits Workflow and Output. Common modules include Attention (emphasis), Constraints (limits), Definition (term explanations), Example (few-shot samples), Fail (fallback logic), Goal, Hack (protection against attacks), Knowledge (reference base), Memory (retaining key information), OutputFormat, Tone, Workflow, and others. Users can add or remove modules as their needs evolve.

“ 6. Building Consistent and Modular Prompts

Two kinds of consistency matter. Format consistency means identifiers keep their meaning throughout: do not use '#' for headings in one place and for variables in another, since this confuses the model's understanding of hierarchy. Content consistency means attribute names match their contents: the Profile should contain the role's résumé-like description, and the Rules section should contain only rules, not skills or workflows. Once comfortable with templates, adapt them. If you need control over output format, add an Output or OutputFormat module. Keep the reasoning chain logical so that each module builds on the previous one.

“ 7. Combining Prompt Techniques

LangGPT's flexible structure integrates well with other prompting techniques: - Detail method: include specific, concrete details to make instructions clearer. - Decomposition method: break complex tasks into simple subtasks, as in 'Let's think step by step', Chain-of-Thought, or LangChain-style pipelines. - Memory method: write instructions that keep the model focused on the task throughout (a system-level prompt). - Explanation method: ask the model to justify its reasoning before answering, as in Chain-of-Thought. - Voting method: have the model produce multiple candidate answers and select the best, as in Tree-of-Thought. - Example method: supply input-output examples, as in one-shot or few-shot prompting. Structured design makes these techniques work together coherently.

“ 8. Automating LangGPT Prompt Generation

Prompt engineers can also automate prompt creation by asking a model to act as a prompt designer. A meta-prompt specifies that the assistant should analyze the user's intent, follow industry best practices, and output a structured prompt in a code block containing a role description, skills, output requirements, workflow, and an initialization greeting. The assistant opens by inviting the user to describe the purpose of the prompt they need. This approach speeds up drafting, though the generated prompts should still be reviewed and tested against real tasks.

“ 9. Practical Exercise: Precise Prompting for Letter Counting

Research has shown that language models sometimes struggle with character-level analysis, for example miscounting letters inside words. The task is to design a prompt that leads a model to correctly answer how many times the letter 'r' appears in 'strawberry'. Step 1 - An unrefined prompt: 'How many letters r are in "strawberry"? Please tell me.' This often yields incorrect answers because the request is ambiguous and gives the model no procedure. Step 2 - A refined structured prompt: - Role: data matching and statistical analyst - Background: the user needs to compare a string against a specified character and count the matches. - Profile: a professional skilled in string processing and pattern recognition. - Goals: identify and count the positions in string A that match character B. - Constraints: ensure accuracy and produce clear results. - OutputFormat: the count of matching positions. - Workflow: read the question; label the string as A and the target character as B; mark matching positions as 1 and others as 0 to form string C; count the 1s; output the count. - Examples: 'hello world' with 'o' yields 3 matches; 'moonshot ai' with 'm' yields 2 matches. - Initialization: greet the user and request the string and character. The explicit step-by-step workflow forces the model to process each character individually, which is what produces the correct answer. Submit the resulting conversation as a screenshot to verify completion.

“ 10. Advanced Projects: Screenplay and Official Document Assistants

Screenplay Assistant: A naive request for a script produces generic results. A LangGPT-structured prompt defines the assistant's skills and output requirements, then specifies character settings (name, personality, backstory, goals, relationships), plot development (main conflict, key events, turning points, ending), dialogue and scene descriptions that fit the characters, and additional parameters such as length, style, and tone. Tested on a model such as InternLM-Chat, the structured prompt yields markedly more specific and coherent output. Official Document Writing Assistant: Simple requests produce vague documents. A structured prompt defines the assistant as a writer of official documents with clear formatting and language standards. It specifies the title, addressee, body structure (purpose and background, detailed main content, summary and requests), attachments, formal language requirements, word limits, and whether legal references or concrete action recommendations are needed. The resulting documents are noticeably more detailed and compliant with conventions.

 Original link: https://zhuanlan.zhihu.com/p/11470727191

Comment(0)

user's avatar

      Related Tools