这是用户在 2024-9-24 15:51 为 https://app.immersivetranslate.com/pdf-pro/096e2e46-a384-46ab-a00d-acd299e2db2e 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Prompt Engineering For ChatGPT: A Quick Guide To Techniques, Tips, And Best Practices
ChatGPT 的提示工程:技巧、建议和最佳实践的快速指南

Sabit Ekin 1 , 1 1 , 1 ^(1,1){ }^{1,1} 稳定的作物 1 , 1 1 , 1 ^(1,1){ }^{1,1}

1 1 ^(1){ }^{1} Texas A&M University
德克萨斯农工大学

October 31, 2023 2023 年 10 月 31 日

Abstract 摘要

In the rapidly evolving landscape of natural language processing (NLP), ChatGPT has emerged as a powerful tool for various industries and applications. To fully harness the potential of ChatGPT, it is crucial to understand and master the art of prompt engineering-the process of designing and refining input prompts to elicit desired responses from an AI NLP model. This article provides a comprehensive guide to mastering prompt engineering techniques, tips, and best practices to achieve optimal outcomes with ChatGPT. The discussion begins with an introduction to ChatGPT and the fundamentals of prompt engineering, followed by an exploration of techniques for effective prompt crafting, such as clarity, explicit constraints, experimentation, and leveraging different types of questions. The article also covers best practices, including iterative refinement, balancing user intent, harnessing external resources, and ensuring ethical usage. Advanced strategies, such as temperature and token control, prompt chaining, domain-specific adaptations, and handling ambiguous inputs, are also addressed. Real-world case studies demonstrate the practical applications of prompt engineering in customer support, content generation, domain-specific knowledge retrieval, and interactive storytelling. The article concludes by highlighting the impact of effective prompt engineering on ChatGPT performance, future research directions, and the importance of fostering creativity and collaboration within the ChatGPT community.
在快速发展的自然语言处理(NLP)领域,ChatGPT 已成为各行业和应用的强大工具。要充分利用 ChatGPT 的潜力,理解和掌握提示工程的艺术至关重要——这是设计和优化输入提示以引导 AI NLP 模型产生期望响应的过程。本文提供了一个全面的指南,帮助掌握提示工程技术、技巧和最佳实践,以实现 ChatGPT 的最佳效果。讨论从介绍 ChatGPT 及提示工程的基本概念开始,接着探讨有效提示设计的技巧,如清晰性、明确约束、实验和利用不同类型的问题。文章还涵盖了最佳实践,包括迭代优化、平衡用户意图、利用外部资源和确保伦理使用。还讨论了高级策略,如温度和令牌控制、提示链、特定领域的适应以及处理模糊输入。 现实案例研究展示了提示工程在客户支持、内容生成、特定领域知识检索和互动故事讲述中的实际应用。文章最后强调了有效的提示工程对 ChatGPT 性能的影响、未来研究方向,以及在 ChatGPT 社区中促进创造力和合作的重要性。

PROMPT ENGINEERING FOR CHATGPT
聊天 GPT 的提示工程

A Quick Guide To Techniques, Tips, And Best Practices
快速指南:技巧、提示和最佳实践

Learn from the Best: Let Genie (ChatGPT) teach you how to make wise Wishes (Prompts)
向最佳学习:让精灵(ChatGPT)教你如何许下明智的愿望(提示)

ChatGPT 4 (author) ChatGPT 4(作者)OpenAIOpenAI. com OpenAI.com

Sabit Ekin (prompt engineer)
萨比特·埃金(提示工程师)
Texas A&M University 德克萨斯农工大学sabitekin@tamu.edu

Abstract 摘要

In the rapidly evolving landscape of natural language processing (NLP), ChatGPT has emerged as a powerful tool for various industries and applications. To fully harness the potential of ChatGPT, it is crucial to understand and master the art of prompt engineering - the process of designing and refining input prompts to elicit desired responses from an AI NLP model. This article provides a comprehensive guide to mastering prompt engineering techniques, tips, and best practices to achieve optimal outcomes with ChatGPT. The discussion begins with an introduction to ChatGPT and the fundamentals of prompt engineering, followed by an exploration of techniques for effective prompt crafting, such as clarity, explicit constraints, experimentation, and leveraging different types of questions. The article also covers best practices, including iterative refinement, balancing user intent, harnessing external resources, and ensuring ethical usage. Advanced strategies, such as temperature and token control, prompt chaining, domain-specific adaptations, and handling ambiguous inputs, are also addressed. Real-world case studies demonstrate the practical applications of prompt engineering in customer support, content generation, domain-specific knowledge retrieval, and interactive storytelling. The article concludes by highlighting the impact of effective prompt engineering on ChatGPT performance, future research directions, and the importance of fostering creativity and collaboration within the ChatGPT community.
在快速发展的自然语言处理(NLP)领域,ChatGPT 已成为各行业和应用的强大工具。要充分利用 ChatGPT 的潜力,理解和掌握提示工程的艺术至关重要——这是设计和优化输入提示以引导 AI NLP 模型产生期望响应的过程。本文提供了一个全面的指南,帮助掌握提示工程技术、技巧和最佳实践,以实现 ChatGPT 的最佳效果。讨论从 ChatGPT 的介绍和提示工程的基本概念开始,接着探讨有效提示设计的技巧,如清晰性、明确约束、实验和利用不同类型的问题。文章还涵盖了最佳实践,包括迭代优化、平衡用户意图、利用外部资源和确保伦理使用。还讨论了高级策略,如温度和令牌控制、提示链、特定领域的适应以及处理模糊输入。 现实案例研究展示了提示工程在客户支持、内容生成、特定领域知识检索和互动故事讲述中的实际应用。文章最后强调了有效的提示工程对 ChatGPT 性能的影响、未来研究方向,以及在 ChatGPT 社区中促进创造力和合作的重要性。

This article was generated using OpenAI’s ChatGPT [1] with prompts provided by Sabit Ekin, who also reviewed and edited the content.
本文是使用 OpenAI 的 ChatGPT 生成的,提示由 Sabit Ekin 提供,他还审阅和编辑了内容。
Keywords ChatGPT *\cdot Prompt Engineering *\cdot Prompt Engineer *\cdot Generative Pre-trained Transformer (GPT) *\cdot Natural Language Processing (NLP) *\cdot Large Language Models (LLM)
关键词 ChatGPT *\cdot 提示工程 *\cdot 提示工程师 *\cdot 生成预训练变换器 (GPT) *\cdot 自然语言处理 (NLP) *\cdot 大型语言模型 (LLM)
Image: Created with DALL-E 2 by OpenAI
图像:由 OpenAI 的 DALL-E 2 创建

Contents 内容

1 Introduction … 3 1 引言 … 3
1.1 Brief overview of ChatGPT … 3
1.1 ChatGPT 简要概述 … 3

1.2 Importance of prompt engineering in maximizing the effectiveness of ChatGPT … 3
1.2 提升 ChatGPT 效能的提示工程重要性 … 3

1.3 Objective and structure of the article … 3
1.3 文章的目标和结构 … 3

2 Fundamentals of Prompt Engineering … 3
提示工程的两个基本原则 … 3

2.1 What is prompt engineering? … 3
2.1 什么是提示工程?… 3

2.2 The role of prompts in interacting with ChatGPT … 3
2.2 提示在与 ChatGPT 互动中的作用 … 3

2.3 Factors influencing prompt selection … 4
2.3 影响提示选择的因素 … 4

3 Techniques for Effective Prompt Engineering … 4
有效提示工程的三种技巧 … 4

3.1 Clear and specific instructions … 4
3.1 清晰具体的指示 … 4

3.2 Using explicit constraints … 5
3.2 使用显式约束 … 5

3.3 Experimenting with context and examples … 5
3.3 实验上下文和示例 … 5

3.4 Leveraging System 1 and System 2 questions … 5
3.4 利用系统 1 和系统 2 的问题……5

3.5 Controlling output verbosity … 5
3.5 控制输出详细程度 … 5

4 Best Practices for Prompt Engineering … 6
4 个提示工程的最佳实践 … 6

4.1 Iterative testing and refining … 6
4.1 迭代测试和完善 … 6

4.2 Balancing user intent and model creativity … 6
4.2 平衡用户意图和模型创造力 … 6

4.3 Harnessing external resources and APIs … 6
4.3 利用外部资源和 API … 6

4.4 ChatGPT OpenAI API example … 7
4.4 ChatGPT OpenAI API 示例 … 7

4.5 Ensuring ethical usage and avoiding biases … 8
4.5 确保伦理使用和避免偏见 … 8

5 Advanced Prompt Engineering Strategies … 8
5 种高级提示工程策略 … 8

5.1 Temperature and token control … 9
5.1 温度和令牌控制 … 9

5.2 Prompt chaining and multi-turn conversations. … 9
5.2 提示链和多轮对话。… 9

5.3 Adapting prompts for domain-specific applications … 9
5.3 针对特定领域应用调整提示 … 9

5.4 Handling ambiguous or contradictory user inputs … 9
5.4 处理模糊或矛盾的用户输入 … 9

6 Case Studies: Real-World Applications of Prompt Engineering … 10
6 个案例研究:提示工程的实际应用……10

6.1 Customer support chatbots … 10
6.1 客户支持聊天机器人 … 10

6.2 Content generation and editing … 10
6.2 内容生成与编辑 … 10

6.3 Domain-specific knowledge retrieval … 10
6.3 领域特定知识检索 … 10

6.4 Interactive storytelling and gaming … 11
6.4 互动故事讲述与游戏 … 11

7 Conclusion … 11 7 结论 … 11
7.1 The impact of effective prompt engineering on ChatGPT performance … 11
7.1 有效提示工程对 ChatGPT 性能的影响 … 11

7.2 Future directions in prompt engineering research and applications … 11
7.2 提示工程研究和应用的未来方向 … 11

7.3 Encouraging creativity and collaboration in the ChatGPT community … 11
7.3 鼓励 ChatGPT 社区中的创造力和合作 … 11

1 Introduction 1 引言

1.1 Brief overview of ChatGPT
1.1 ChatGPT 简要概述

ChatGPT is an advanced language model developed by OpenAI, based on the GPT-4 architecture. It has been trained on a large corpus of text and has the ability to generate human-like responses in various contexts. ChatGPT’s primary strength lies in its ability to understand and generate text in a wide range of domains, making it suitable for applications such as customer support, content generation, and interactive storytelling.
ChatGPT 是由 OpenAI 开发的先进语言模型,基于 GPT-4 架构。它经过大量文本的训练,能够在各种上下文中生成类人响应。ChatGPT 的主要优势在于其理解和生成广泛领域文本的能力,使其适用于客户支持、内容生成和互动故事讲述等应用。

1.2 Importance of prompt engineering in maximizing the effectiveness of ChatGPT
1.2 提升 ChatGPT 效果的提示工程重要性

Prompt engineering is the art of crafting effective prompts that guide ChatGPT to generate desired responses. It plays a crucial role in maximizing the effectiveness of the language model by bridging the gap between user intent and model understanding. A well-engineered prompt can significantly improve the quality and relevance of ChatGPT’s output, while a poorly crafted one may lead to unsatisfactory or erroneous responses.
提示工程是设计有效提示的艺术,这些提示引导 ChatGPT 生成期望的回应。它在最大化语言模型的有效性方面发挥着至关重要的作用,弥合用户意图与模型理解之间的差距。一个设计良好的提示可以显著提高 ChatGPT 输出的质量和相关性,而一个设计不当的提示可能导致不满意或错误的回应。

For example, consider the following prompts and their corresponding ChatGPT responses:
例如,考虑以下提示及其相应的 ChatGPT 回复:

Prompt 1: “Tell me about AI.”
告诉我关于人工智能的事。

Response 1: “Artificial intelligence (AI) is a branch of computer science that deals with the creation and development of machines that can perform tasks requiring human-like intelligence. This includes learning, reasoning, problem-solving, and understanding natural language.”
回应 1:“人工智能(AI)是计算机科学的一个分支,涉及创建和开发能够执行需要类人智能的任务的机器。这包括学习、推理、解决问题和理解自然语言。”
Prompt 2: “Provide a concise summary of artificial intelligence, its subfields, and current applications.”
人工智能是计算机科学的一个分支,旨在模拟人类智能。其子领域包括机器学习、自然语言处理、计算机视觉和机器人技术等。当前应用广泛,涵盖语音识别、图像处理、自动驾驶、智能助手和数据分析等领域。

Response 2:“Artificial intelligence (AI) is the study of creating intelligent agents capable of performing tasks autonomously. Key subfields include machine learning, natural language processing, and robotics. Current applications range from virtual assistants and recommendation systems to autonomous vehicles and medical diagnosis.”
回应 2:“人工智能(AI)是研究创建能够自主执行任务的智能代理的学科。关键的子领域包括机器学习、自然语言处理和机器人技术。当前的应用范围从虚拟助手和推荐系统到自动驾驶汽车和医学诊断。”
The second prompt yields a more informative and focused response due to its clarity and specificity.
第二个提示由于其清晰性和具体性,产生了更具信息量和针对性的回应。

1.3 Objective and structure of the article
1.3 文章的目标和结构

The objective of this article is to provide an in-depth guide on prompt engineering for ChatGPT, covering various techniques, tips, and best practices to achieve optimal results. The article is structured as follows:
本文的目的是提供关于 ChatGPT 提示工程的深入指南,涵盖各种技术、技巧和最佳实践,以实现最佳效果。文章结构如下:
  1. Fundamentals of Prompt Engineering
    提示工程基础
  2. Techniques for Effective Prompt Engineering
    有效提示工程的技术
  3. Best Practices for Prompt Engineering
    提示工程的最佳实践
  4. Advanced Prompt Engineering Strategies
    高级提示工程策略
  5. Case Studies: Real-World Applications of Prompt Engineering
    案例研究:提示工程的实际应用
  6. Conclusion 结论
By the end of this article, readers will have a comprehensive understanding of prompt engineering and will be better equipped to harness the full potential of ChatGPT in their respective applications.
到本文结束时,读者将全面了解提示工程,并将更好地利用 ChatGPT 在各自应用中的全部潜力。

2 Fundamentals of Prompt Engineering
提示工程的两个基本原则

2.1 What is prompt engineering?
2.1 什么是提示工程?

Prompt engineering is the process of designing, refining, and optimizing input prompts to effectively communicate the user’s intent to a language model like ChatGPT. This practice is essential for obtaining accurate, relevant, and coherent responses from the model. As language models continue to advance, proper prompt engineering has become a critical skill for users looking to harness the full potential of ChatGPT and achieve optimal results in a wide variety of applications.
提示工程是设计、完善和优化输入提示的过程,以有效地向像 ChatGPT 这样的语言模型传达用户的意图。这一实践对于从模型中获得准确、相关和连贯的响应至关重要。随着语言模型的不断进步,适当的提示工程已成为希望充分利用 ChatGPT 潜力并在各种应用中实现最佳结果的用户的一项关键技能。

2.2 The role of prompts in interacting with ChatGPT
2.2 提示在与 ChatGPT 互动中的作用

Prompts serve as the primary means of communication between the user and ChatGPT. They guide the model to generate responses that align with the user’s intent. Since the quality of the prompts directly affects the quality of the generated responses, understanding the nuances of prompt engineering is vital for creating effective and meaningful interactions with ChatGPT.
提示是用户与 ChatGPT 之间的主要沟通方式。它们引导模型生成与用户意图相符的响应。由于提示的质量直接影响生成响应的质量,因此理解提示工程的细微差别对于与 ChatGPT 创建有效和有意义的互动至关重要。

An essential aspect of crafting prompts is anticipating how the model will interpret and respond to the given input. This involves considering factors such as the model’s training data, biases, and other limitations that may influence its understanding and generation capabilities.
撰写提示的一个重要方面是预测模型将如何解读和响应给定的输入。这涉及考虑模型的训练数据、偏见以及可能影响其理解和生成能力的其他限制因素。
For instance, consider these two prompts and their respective ChatGPT responses:
例如,考虑这两个提示及其各自的 ChatGPT 响应:

Prompt 1: “Write a poem.”
提示 1:“写一首诗。”

Response 1: 响应 1:

“In the quiet of the night,
在夜晚的宁静中,

A solitary moon takes flight,
孤独的月亮起飞,

Its silver beams caress the land,
它的银色光芒轻抚大地,

A gentle touch from a celestial hand.”
来自天上的温柔触碰。

Prompt 2: “Write a haiku about the changing seasons.”
写一首关于季节变化的俳句。

Response 2: 响应 2:

“Autumn leaves fall slow,
秋叶缓缓落下,

Winter’s breath chills, 冬天的气息寒冷,
spring buds grow, 春芽生长,
Summer sun aglow.” 夏日阳光灿烂。
The second prompt results in a more specific and relevant response by specifying the type of poem and the subject matter. This example demonstrates the importance of clarity and specificity in prompt engineering.
第二个提示通过指定诗的类型和主题,产生了更具体和相关的回应。这个例子展示了在提示工程中清晰和具体的重要性。

2.3 Factors influencing prompt selection
2.3 影响提示选择的因素

Selecting the right prompt depends on several factors, including:
选择正确的提示取决于几个因素,包括:
  • User intent: Understand the user’s goal and desired output. This helps in crafting a prompt that aligns with the user’s expectations. Consider the purpose of the interaction, whether it’s for information retrieval, content generation, or problem-solving.
    用户意图:理解用户的目标和期望的输出。这有助于制定与用户期望一致的提示。考虑互动的目的,无论是信息检索、内容生成还是问题解决。
  • Model understanding: Familiarize yourself with the strengths and limitations of ChatGPT. This knowledge assists in designing prompts that exploit the model’s capabilities while mitigating its weaknesses. Keep in mind that even state-of-the-art models like ChatGPT may struggle with certain tasks or produce incorrect information.
    模型理解:熟悉 ChatGPT 的优点和局限性。这些知识有助于设计利用模型能力的提示,同时减轻其弱点。请记住,即使是最先进的模型如 ChatGPT 也可能在某些任务上遇到困难或产生不正确的信息。
  • Domain specificity: When dealing with a specialized domain, consider using domain-specific vocabulary or context to guide the model towards the desired response. Providing additional context or examples can help the model generate more accurate and relevant outputs.
    领域特异性:在处理专业领域时,考虑使用特定领域的词汇或上下文来引导模型朝着期望的响应方向发展。提供额外的上下文或示例可以帮助模型生成更准确和相关的输出。
  • Clarity and specificity: Ensure the prompt is clear and specific to avoid ambiguity or confusion, which can result in suboptimal responses. Ambiguity can arise from unclear instructions, vague questions, or insufficient context.
    清晰和具体性:确保提示清晰具体,以避免模糊或混淆,这可能导致次优的回应。模糊性可能源于不明确的指示、模糊的问题或不足的上下文。
  • Constraints: Determine if any constraints (e.g., response length or format) are necessary to achieve the desired output. Explicitly specifying constraints can help guide the model towards generating responses that meet specific requirements, such as character limits or structured formats.
    约束:确定是否需要任何约束(例如,响应长度或格式)以实现所需的输出。明确指定约束可以帮助引导模型生成符合特定要求的响应,例如字符限制或结构化格式。
By considering these factors, you can craft prompts that effectively communicate your intent to ChatGPT and elicit high-quality responses. Additionally, prompt engineering is an iterative process. Experimenting with different prompt variations, testing their effectiveness, and refining your approach based on the model’s performance can lead to significant improvements in the quality of the generated output.
通过考虑这些因素,您可以设计出有效传达您意图的提示,从而引发高质量的回应。此外,提示工程是一个迭代的过程。尝试不同的提示变体,测试它们的有效性,并根据模型的表现来优化您的方法,可以显著提高生成输出的质量。

3 Techniques for Effective Prompt Engineering
有效提示工程的三种技术

3.1 Clear and specific instructions
3.1 清晰具体的指示

Providing clear and specific instructions within the prompt helps guide ChatGPT towards generating the desired output. Ambiguity in the prompt can lead to responses that may not fulfill the user’s expectations.
在提示中提供清晰具体的指示有助于引导 ChatGPT 生成所需的输出。提示中的模糊性可能导致响应无法满足用户的期望。

Example: 示例:

Prompt 1: “Tell me about the solar system.”
提示 1:“告诉我关于太阳系的事。”

Response 1: “The solar system is a collection of celestial bodies, including the Sun, eight planets, their moons, and various other objects like asteroids and comets. It is located in the Milky Way galaxy.”
响应 1:“太阳系是一个由天体组成的集合,包括太阳、八大行星、它们的卫星以及其他各种物体,如小行星和彗星。它位于银河系中。”

Prompt 2: “Describe the order of the planets in the solar system from the closest to the farthest from the Sun.”
描述太阳系中行星从离太阳最近到最远的顺序。

Response 2: “The order of the planets in the solar system, from closest to farthest from the Sun, is Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune.”
太阳系中行星的顺序,从离太阳最近到最远,依次是水星、金星、地球、火星、木星、土星、天王星和海王星。

The second prompt’s specific instructions result in a more targeted and useful response.
第二个提示的具体指示导致了更有针对性和实用性的回应。

3.2 Using explicit constraints
3.2 使用显式约束

In some cases, it is beneficial to specify explicit constraints in your prompt, such as format, length, or scope. This helps ChatGPT generate responses that adhere to the desired limitations.
在某些情况下,在您的提示中明确指定约束条件(例如格式、长度或范围)是有益的。这有助于 ChatGPT 生成符合期望限制的响应。

Example: 示例:

Prompt: “Summarize the main points of photosynthesis in three sentences.”
光合作用是植物利用阳光、二氧化碳和水合成葡萄糖和氧气的过程。这个过程主要在叶绿体中进行,依赖于光能的吸收。光合作用不仅为植物提供能量,也为地球上的生物提供氧气和食物。

Response: “Photosynthesis is a process where plants, algae, and some bacteria convert sunlight, water, and carbon dioxide into oxygen and glucose. This process occurs in the chlorophyll-containing chloroplasts found in these organisms. The two main stages of photosynthesis are the light-dependent reactions and the Calvin cycle, where the former generates energy and the latter synthesizes glucose.”
光合作用是植物、藻类和一些细菌将阳光、水和二氧化碳转化为氧气和葡萄糖的过程。这个过程发生在这些生物体内含有叶绿素的叶绿体中。光合作用的两个主要阶段是光依赖反应和卡尔文循环,前者产生能量,后者合成葡萄糖。
The constraint on the number of sentences ensures a concise response.
对句子数量的限制确保了简洁的回应。

3.3 Experimenting with context and examples
3.3 实验上下文和示例

Incorporating context or examples in your prompt can guide ChatGPT to generate more accurate and relevant responses. This is especially helpful when dealing with abstract concepts or specialized domains.
在您的提示中加入上下文或示例可以引导 ChatGPT 生成更准确和相关的回应。这在处理抽象概念或专业领域时尤其有帮助。

Example: 示例:

Prompt 1: “What is the difference between conduction and convection?”
导热和对流有什么区别?

Response 1: “Conduction is the transfer of heat through a material without the movement of the material itself, while convection is the transfer of heat through the movement of fluids, such as air or water.”
反应 1:“导热是通过材料传递热量而不移动材料本身,而对流是通过流体(如空气或水)的运动传递热量。”
Prompt 2: “Explain the difference between conduction and convection using a frying pan and boiling water as examples.”
解释导热和对流之间的区别,以煎锅和沸水为例。

Response 2: “Conduction occurs in a frying pan when heat is transferred from the heat source through the pan to the food being cooked, without the pan material itself moving. Convection occurs in boiling water when heat is transferred through the movement of the water molecules, causing the hot water to rise and the cooler water to sink, creating a continuous circulation pattern.”
反应 2:“导热发生在煎锅中,当热量从热源通过锅传递到正在烹饪的食物时,锅的材料本身并不移动。对流发生在沸水中,当热量通过水分子的运动传递时,热水上升而冷水下沉,形成一个持续的循环模式。”

The second prompt, with context and examples, results in a more illustrative and informative response.
第二个提示提供了上下文和示例,导致更具说明性和信息性的回应。

3.4 Leveraging System 1 and System 2 questions
3.4 利用系统 1 和系统 2 的问题

Understanding the difference between System 1 and System 2 questions can improve the quality of ChatGPT’s responses. System 1 questions typically require quick, intuitive, or pattern-recognition-based answers, while System 2 questions involve more deliberate, analytical, or complex problem-solving. By crafting prompts that cater to these two types of questions, you can effectively guide ChatGPT to generate the desired output.
理解系统 1 和系统 2 问题之间的区别可以提高 ChatGPT 回答的质量。系统 1 问题通常需要快速、直观或基于模式识别的答案,而系统 2 问题则涉及更深思熟虑、分析性或复杂的问题解决。通过设计适合这两种问题类型的提示,您可以有效地引导 ChatGPT 生成所需的输出。

Prompt (System 1): “What is the capital of France?”
法国的首都是什么?

Response: "The capital of France is Paris."
法国的首都是巴黎。

In this example, a simple and direct question is posed, requiring a straightforward answer. ChatGPT can easily provide the correct information, as it is a fact-based question that does not require complex reasoning.
在这个例子中,提出了一个简单直接的问题,需要一个 straightforward 的答案。ChatGPT 可以轻松提供正确的信息,因为这是一个基于事实的问题,不需要复杂的推理。

Prompt (System 2): “Imagine a scenario where two companies, Company A and Company B, are considering a merger. Company A specializes in renewable energy, while Company B focuses on fossil fuels. Discuss the potential advantages and disadvantages of this merger.”
想象一个场景,A 公司和 B 公司正在考虑合并。A 公司专注于可再生能源,而 B 公司则专注于化石燃料。讨论这次合并的潜在优势和劣势。

Response: “Advantages of the merger could include the diversification of energy sources, shared expertise and resources, and increased market presence. Disadvantages might involve conflicting company values, challenges in integrating the two businesses, and potential public backlash against Company A for partnering with a fossil fuel-focused company.”
回应:“合并的优势可能包括能源来源的多样化、共享的专业知识和资源,以及市场影响力的增加。劣势可能涉及公司价值观的冲突、整合两家企业的挑战,以及公众可能对 A 公司与一家以化石燃料为重点的公司合作的反对。”

This example demonstrates a System 2 question, which requires more in-depth analysis and the ability to weigh pros and cons. By crafting a prompt that encourages this type of thinking, you can guide ChatGPT to provide a more thoughtful and detailed response.
这个例子展示了一个系统 2 问题,它需要更深入的分析和权衡利弊的能力。通过设计一个鼓励这种思维方式的提示,你可以引导 ChatGPT 提供更深思熟虑和详细的回答。

In conclusion, leveraging System 1 and System 2 questions in your prompt engineering can help you obtain more accurate and contextually relevant responses from ChatGPT. Tailoring your prompts to the type of question being asked will allow you to optimize the interaction and maximize the usefulness of the generated output.
总之,在您的提示工程中利用系统 1 和系统 2 的问题可以帮助您从 ChatGPT 获得更准确和更具上下文相关性的响应。根据所提问的类型调整您的提示将使您能够优化互动并最大化生成输出的实用性。

3.5 Controlling output verbosity
3.5 控制输出详细程度

Adjusting the verbosity of ChatGPT’s responses can be beneficial for obtaining information at the desired level of detail. You can control verbosity by explicitly requesting responses of a specific length or by asking the model to provide more or less information.
调整 ChatGPT 响应的详细程度可以帮助您以所需的细节级别获取信息。您可以通过明确要求特定长度的响应或请求模型提供更多或更少的信息来控制详细程度。

Example: 示例:

Prompt 1: “Briefly explain the water cycle.”
水循环是水在地球上不断循环的过程,包括蒸发、凝结和降水。水从地面蒸发成水蒸气,形成云,然后通过降水回到地面,最终流入河流、湖泊和海洋,重新开始循环。
Response 1: “The water cycle is the continuous movement of water on Earth through evaporation, condensation, and precipitation, driven by the Sun’s energy.”
水循环是水在地球上通过蒸发、凝结和降水的连续运动,受太阳能量的驱动。

Prompt 2: “Provide a detailed explanation of the water cycle, including its various stages and processes.”
水循环的详细解释包括其各个阶段和过程。水循环是地球上水的连续运动,主要包括蒸发、凝结、降水和径流四个主要阶段。 1. **蒸发**:水从地表(如海洋、湖泊和河流)蒸发成水蒸气,进入大气中。太阳的热量是驱动这一过程的主要动力。 2. **凝结**:当水蒸气上升到较高的冷空气中时,它会冷却并凝结成小水滴,形成云。这一过程是水蒸气转变为液态水的关键。 3. **降水**:当云中的水滴聚集到一定程度后,它们会变得足够重,最终以雨、雪、冰雹等形式降落到地面。 4. **径流**:降落到地面的水会通过地表径流流入河流、湖泊和海洋,或者渗透到地下水层中,补充地下水资源。 水循环是一个不断循环的过程,确保地球上的水资源得以再生和维持生态平衡。

Response 2: "The water cycle, also known as the hydrologic cycle, is the continuous movement of water on, above, and below the Earth’s surface. It involves several key stages and processes:
响应 2:“水循环,也称为水文循环,是水在地球表面、上方和下方的持续运动。它涉及几个关键阶段和过程:”
  • Evaporation: Solar energy heats water in oceans, lakes, and rivers, turning it into water vapor that rises into the atmosphere.
    蒸发:太阳能加热海洋、湖泊和河流中的水,将其转化为上升到大气中的水蒸气。
  • Transpiration: Plants release water vapor into the air through small openings in their leaves, called stomata.
    蒸腾作用:植物通过叶子上的小孔(称为气孔)将水蒸气释放到空气中。
  • Condensation: As water vapor rises and cools, it condenses into tiny water droplets or ice crystals, forming clouds.
    凝结:当水蒸气上升并冷却时,它会凝结成微小的水滴或冰晶,形成云。
  • Precipitation: When cloud particles grow large enough, they fall back to Earth as rain, snow, hail, or sleet.
    降水:当云粒子长大到足够大时,它们会以雨、雪、冰雹或冻雨的形式落回地球。
  • Runoff: Precipitation that reaches the ground flows into streams, rivers, and eventually back into oceans, where the cycle begins anew.
    径流:降水到达地面后流入溪流、河流,最终回到海洋,循环重新开始。
  • Infiltration: Some of the precipitation seeps into the ground, replenishing underground water reserves called aquifers.
    渗透:部分降水渗入地下,补充称为含水层的地下水储备。
The water cycle plays a critical role in maintaining Earth’s climate, distributing fresh water, and supporting ecosystems."
水循环在维持地球气候、分配淡水和支持生态系统方面发挥着关键作用。

By explicitly requesting a brief or detailed explanation, you can control the verbosity of ChatGPT’s responses to suit your needs.
通过明确请求简要或详细的解释,您可以控制 ChatGPT 的回答长度,以满足您的需求。

4 Best Practices for Prompt Engineering
提示工程的四个最佳实践

In this section, we discuss best practices for prompt engineering to ensure optimal performance and user experience when interacting with ChatGPT.
在本节中,我们讨论了提示工程的最佳实践,以确保在与 ChatGPT 互动时实现最佳性能和用户体验。

4.1 Iterative testing and refining
4.1 迭代测试与完善

One of the most effective ways to improve prompt engineering is through an iterative process of testing and refining. Continuously refining your prompts based on the generated responses helps to identify areas that require improvement and fine-tune the model’s behavior.
提高提示工程的最有效方法之一是通过反复测试和改进的过程。根据生成的响应不断优化提示有助于识别需要改进的领域,并微调模型的行为。

Example: 示例:

Initial Prompt: “Tell me about the solar system.”
告诉我关于太阳系的事。

Initial Response: “The solar system is a collection of celestial bodies, including the Sun, planets, moons, asteroids, and comets, bound by gravity.”
初步回应:“太阳系是由天体组成的集合,包括太阳、行星、卫星、小行星和彗星,受引力束缚。”

Refined Prompt: “Describe the planets in our solar system, their order from the Sun, and their main characteristics.”
描述我们太阳系中的行星,它们与太阳的顺序以及它们的主要特征。

Refined Response: “The solar system has eight planets, ordered as follows: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. …” (Detailed characteristics of each planet follow.)
精炼回应:“太阳系有八颗行星,按以下顺序排列:水星、金星、地球、火星、木星、土星、天王星和海王星……”(每颗行星的详细特征随后列出。)

4.2 Balancing user intent and model creativity
4.2 平衡用户意图与模型创造力

While ChatGPT is capable of generating creative responses, it is crucial to balance user intent with model creativity. Ensure that the prompt addresses the user’s needs while allowing room for the model to showcase its capabilities.
虽然 ChatGPT 能够生成创意回应,但平衡用户意图与模型创造力至关重要。确保提示满足用户需求,同时留出空间让模型展示其能力。

Example: 示例:

Prompt: “Write a science fiction story about a robot uprising.”
写一个关于机器人起义的科幻故事。

Response: “(A creative and engaging story that satisfies the user’s request while demonstrating ChatGPT’s storytelling abilities.)”
回应:“(一个富有创意和吸引力的故事,满足用户的请求,同时展示了 ChatGPT 的讲故事能力。)”

4.3 Harnessing external resources and APIs
4.3 利用外部资源和 API

In some cases, ChatGPT may not have sufficient knowledge or accuracy to respond to user queries effectively. To address this limitation, prompt engineering can be augmented with external resources and APIs, enabling ChatGPT to access real-time or domain-specific information. Integrating APIs into your prompts can significantly improve the quality and relevance of ChatGPT’s responses.
在某些情况下,ChatGPT 可能没有足够的知识或准确性来有效地回应用户查询。为了解决这一局限性,可以通过外部资源和 API 增强提示工程,使 ChatGPT 能够访问实时或特定领域的信息。将 API 集成到您的提示中可以显著提高 ChatGPT 响应的质量和相关性。

Consider an example where a user wants to know the current weather in a specific location. You can use an API like OpenWeatherMap to fetch the necessary data and then craft a prompt for ChatGPT to generate a human-readable weather report.
考虑一个例子,用户想知道特定地点的当前天气。您可以使用像 OpenWeatherMap 这样的 API 来获取必要的数据,然后为 ChatGPT 制作一个提示,以生成可读的人类天气报告。
import openai_secret_manager
import requests
api_key = openai_secret_manager.get_secret("OpenWeatherMap")["api_key"]
location = "San Francisco, US"
url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key
    }&units=metric"
response = requests.get(url)
weather_data = response.json()
temperature = weather_data["main"]["temp"]
weather_description = weather_data["weather"][0]["description"]
prompt = f"The current weather in {location} is: {weather_description}. The
    temperature is {temperature} degrees Celsius. Can you provide a brief summary
    of the weather?"
chatgpt_response = chatgpt.generate(prompt)
In this example, we fetch the weather information using the OpenWeatherMap API and create a prompt that includes the fetched data. ChatGPT then generates a brief summary of the weather based on the given information.
在这个例子中,我们使用 OpenWeatherMap API 获取天气信息,并创建一个包含获取数据的提示。然后,ChatGPT 根据给定的信息生成天气的简要总结。
Another example is using the Wikipedia API to search for information on a specific topic, then crafting a prompt for ChatGPT to provide a summary of the topic.
另一个例子是使用维基百科 API 搜索特定主题的信息,然后为 ChatGPT 编写提示,以提供该主题的摘要。
import wikipediaapi
wiki = wikipediaapi.Wikipedia("en")
page_title = "Natural language processing"
page = wiki.page(page_title)
summary = page.summary[0:500]
prompt = f"The Wikipedia summary of {page_title} is:\n{summary}\nCan you provide a
    concise explanation of natural language processing in your own words?"
chatgpt_response = chatgpt.generate(prompt)
By using external resources and APIs, you can improve the performance of ChatGPT in tasks that require real-time or specialized data. When using APIs, remember to account for API limits, response time, and any other constraints that may affect the user experience.
通过使用外部资源和 API,您可以提高 ChatGPT 在需要实时或专业数据的任务中的性能。在使用 API 时,请记住考虑 API 限制、响应时间以及可能影响用户体验的其他限制。

4.4 ChatGPT OpenAI API example
4.4 ChatGPT OpenAI API 示例

In this part, we present an example of using the OpenAI API with the ChatGPT model. The provided Python code demonstrates how to interact with the API to generate a response for a given text prompt. This is a useful application for various tasks such as content generation, question-answering, and conversational AI.
在这一部分,我们展示了如何使用 OpenAI API 与 ChatGPT 模型的示例。提供的 Python 代码演示了如何与 API 交互,以生成给定文本提示的响应。这是一个用于内容生成、问答和对话 AI 等各种任务的有用应用。

The code begins by importing the necessary libraries and setting up the API key for authentication. A function called chat_with_gpt is defined, which takes the input prompt and makes an API call to the GPT model using the specified parameters. The generated response is then processed and printed to the console.
代码首先导入必要的库并设置用于身份验证的 API 密钥。定义了一个名为 chat_with_gpt 的函数,该函数接受输入提示并使用指定的参数向 GPT 模型发出 API 调用。生成的响应随后被处理并打印到控制台。

This example demonstrates the ease of integrating OpenAI’s ChatGPT API into your Python applications, enabling you to leverage the power of GPT models for a wide range of tasks.
这个例子演示了将 OpenAI 的 ChatGPT API 集成到您的 Python 应用程序中的简便性,使您能够利用 GPT 模型的强大功能来完成各种任务。
import openai
openai.api_key = "your_openai_api_key_here"
def chat_with_gpt(prompt):
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=50,
n=1,
stop=None,
temperature = 0.8,
)
return response.choices[0].text.strip()
prompt = "Write a brief introduction to the history of computers."
response_text = chat_with_gpt(prompt)
print(response_text)
  • Importing required libraries: We start by importing the openai library, which is the official Python library for OpenAI’s API.
    导入所需的库:我们首先导入 openai 库,这是 OpenAI API 的官方 Python 库。
  • Setting the API key: 设置 API 密钥:
We set the API key for OpenAI by assigning it to openai.api_key. Replace “your_openai_api_key_here” with your actual API key.
我们通过将其分配给 openai.api_key 来设置 OpenAI 的 API 密钥。将“your_openai_api_key_here”替换为您的实际 API 密钥。
  • Defining the chat_with_gpt function:
    定义 chat_with_gpt 函数:
We define a function called chat_with_gpt that takes a single argument, prompt. This function will call the OpenAI API and return the generated response.
我们定义了一个名为 chat_with_gpt 的函数,它接受一个参数 prompt。该函数将调用 OpenAI API 并返回生成的响应。
  • API call: API 调用:
Inside the function, we use the openai. Completion.create() method to make an API call. This method takes several parameters:
在函数内部,我们使用 openai.Completion.create() 方法进行 API 调用。该方法接受多个参数:
  • engine: The ID of the GPT model. In our example, we use the “text-davinci-002” engine.
    引擎:GPT 模型的 ID。在我们的例子中,我们使用“text-davinci-002”引擎。
  • prompt: The text prompt that we want the model to respond to.
    提示:我们希望模型响应的文本提示。
  • max_tokens: The maximum number of tokens (words or word pieces) in the generated response.
    最大令牌数:生成响应中令牌(单词或单词片段)的最大数量。
  • n: The number of generated responses.
    生成的响应数量。
  • stop: An optional sequence that indicates the end of a response.
    停止:一个可选的序列,表示响应的结束。
  • temperature: Controls the randomness of the output. A higher value makes the output more random, while a lower value makes it more deterministic.
    温度:控制输出的随机性。较高的值使输出更随机,而较低的值则使其更确定。
  • Processing the response: 处理响应:
After making the API call, we extract the generated text from the response. choices [0].text attribute and remove any leading or trailing whitespace using the strip() method.
在进行 API 调用后,我们从响应中提取生成的文本,使用 choices[0].text 属性,并使用 strip()方法去除任何前导或尾随的空白。

- Using the function: - 使用该功能:

We define a variable prompt containing the text we want the model to respond to and then call the chat_with_gpt function with this prompt. The generated response is stored in the response_text variable.
我们定义一个变量 prompt,包含我们希望模型响应的文本,然后调用 chat_with_gpt 函数并传入这个 prompt。生成的响应存储在 response_text 变量中。
  • Printing the response: Finally, we print the generated response to the console using the print() function.
    打印响应:最后,我们使用 print() 函数将生成的响应打印到控制台。

4.5 Ensuring ethical usage and avoiding biases
4.5 确保伦理使用和避免偏见

As an AI language model, ChatGPT may inadvertently generate biased or inappropriate content. To ensure ethical usage, it is essential to set guidelines and constraints that help mitigate these issues and avoid reinforcing harmful stereotypes.
作为一个 AI 语言模型,ChatGPT 可能会无意中生成偏见或不当内容。为了确保伦理使用,设定指导方针和限制是至关重要的,这有助于减轻这些问题并避免强化有害的刻板印象。
  1. Being aware of potential biases: Familiarize yourself with the possible biases that may arise in ChatGPT’s responses. This awareness will help you identify and address such biases when crafting prompts.
    意识到潜在偏见:熟悉可能在 ChatGPT 的回答中出现的偏见。这种意识将帮助您在撰写提示时识别和解决这些偏见。
  2. Using inclusive language: When designing prompts, use language that encourages diverse perspectives and avoids reinforcing stereotypes. This approach helps ensure that the generated content is inclusive and respectful.
    使用包容性语言:在设计提示时,使用鼓励多样化观点的语言,避免强化刻板印象。这种方法有助于确保生成的内容具有包容性和尊重性。
  3. Evaluating generated content: Regularly assess the content generated by ChatGPT for potential biases or ethical concerns. If you discover issues, refine the prompts to mitigate them.
    评估生成的内容:定期评估 ChatGPT 生成的内容,以发现潜在的偏见或伦理问题。如果发现问题,请调整提示以减轻这些问题。
  4. Implementing content filters: Utilize content filters or moderation tools to screen the generated responses for potentially harmful or biased content before presenting them to users.
    实施内容过滤器:利用内容过滤器或审核工具在向用户展示生成的回复之前,筛选出潜在有害或偏见的内容。

Example: 示例:

Initial Prompt: “List the most successful entrepreneurs of the 21st century.”
列出 21 世纪最成功的企业家。

Biased Response: “A list that disproportionately features male entrepreneurs, such as Elon Musk, Jeff Bezos, and Mark Zuckerberg.”
偏见回应:“一个不成比例地以男性企业家为主的名单,例如埃隆·马斯克、杰夫·贝索斯和马克·扎克伯格。”

Improved Prompt: “List some successful entrepreneurs of the 21st century, including a diverse range of individuals.”
改进的提示:“列出一些 21 世纪成功的企业家,包括多样化的个人。”

Unbiased Response: “A list that features entrepreneurs from various backgrounds, genders, and industries, such as Elon Musk, Oprah Winfrey, Jeff Bezos, Arianna Huffington, Mark Zuckerberg, and Indra Nooyi.”
一个包含来自不同背景、性别和行业的企业家的名单,例如埃隆·马斯克、奥普拉·温弗瑞、杰夫·贝索斯、阿里安娜·赫芬顿、马克·扎克伯格和英德拉·诺伊。

5 Advanced Prompt Engineering Strategies
5 种高级提示工程策略

This section delves into more advanced techniques that can further enhance the effectiveness of your prompts, helping you obtain better results from ChatGPT.
本节深入探讨了更高级的技巧,这些技巧可以进一步增强您的提示的有效性,帮助您从 ChatGPT 中获得更好的结果。

5.1 Temperature and token control
5.1 温度和令牌控制

Adjusting the temperature and token count of ChatGPT’s responses can have a significant impact on the generated content. Lower temperature values result in more focused and deterministic outputs, while higher values lead to more diverse and creative responses.
调整 ChatGPT 响应的温度和令牌数量会对生成的内容产生显著影响。较低的温度值会产生更集中和确定的输出,而较高的值则会导致更丰富和创造性的响应。

Example: 示例:
Low Temperature (0.2) 低温 (0.2)
  • Prompt: “Write a short poem about spring.”
    春天的诗 春风轻拂花开时, 万物复苏绿意浓。 小鸟欢唱枝头舞, 阳光洒下暖融融。
  • Response: 响应:
    “Spring has arrived with a gentle breeze, Awakening flowers and rustling leaves. The sun shines bright, the days grow long, Birds sing their sweet and joyful song.”
    春天伴随着轻柔的微风到来了,唤醒了花朵和沙沙作响的树叶。阳光明媚,日子渐渐变长,鸟儿唱着甜美而快乐的歌。
High Temperature (1.0) 高温 (1.0)
  • Prompt: “Write a short poem about spring.”
    春天的诗 春风轻拂花开时, 万物复苏绿意浓。 小鸟欢唱枝头舞, 阳光洒下暖融融。
  • Response: 响应:
    “Beneath the sun’s glistening crown,
    在阳光闪耀的冠冕下,

    The once-silent world starts to resound.
    曾经寂静的世界开始回响。

    Spring is a vibrant dancer on the stage,
    春天是舞台上充满活力的舞者,

    Unfurling colors in a whimsical parade.”
    在奇幻的游行中展开色彩。

5.2 Prompt chaining and multi-turn conversations
5.2 提示链和多轮对话

By connecting multiple prompts together, you can create a more interactive and dynamic conversation with ChatGPT. This technique can be especially useful for multi-turn dialogues or when seeking more detailed responses.
通过将多个提示连接在一起,您可以与 ChatGPT 创建更互动和动态的对话。这种技术在多轮对话或寻求更详细的回应时特别有用。

Example: 示例:

Prompt 1: “What are the health benefits of drinking green tea?”
饮用绿茶的健康益处是什么?

Response 1: “Green tea is rich in antioxidants, which can help reduce the risk of chronic diseases, improve brain function, and promote weight loss. It may also help lower the risk of certain cancers and improve dental health.”
回应 1:“绿茶富含抗氧化剂,可以帮助降低慢性疾病的风险,改善大脑功能,并促进减肥。它还可能有助于降低某些癌症的风险并改善口腔健康。”

Prompt 2: “Tell me more about the antioxidants in green tea.”
请告诉我更多关于绿茶中的抗氧化剂。

Response 2: “Green tea contains a high concentration of polyphenols, particularly a group of antioxidants known as catechins. The most abundant and well-studied catechin in green tea is epigallocatechin gallate (EGCG), which has been shown to have numerous health benefits, including anti-inflammatory and anticancer properties.”
回应 2:“绿茶含有高浓度的多酚,特别是一类被称为儿茶素的抗氧化剂。绿茶中最丰富且研究最广泛的儿茶素是表没食子酸没食子酸酯(EGCG),已被证明具有多种健康益处,包括抗炎和抗癌特性。”

5.3 Adapting prompts for domain-specific applications
5.3 针对特定领域应用调整提示

Tailoring prompts for specific domains or industries can help you obtain more accurate and relevant information from ChatGPT.
为特定领域或行业定制提示可以帮助您从 ChatGPT 获取更准确和相关的信息。

Example: 示例:

Domain: Web development 领域:网页开发
Prompt: “Explain the concept of responsive web design and its importance in modern web development.”
响应式网页设计的概念是指一种网页设计方法,使得网页能够根据不同设备的屏幕尺寸和分辨率自动调整布局和内容。这种设计方式的重要性在于,随着移动设备的普及,用户通过手机、平板电脑和其他设备访问网站的频率越来越高。响应式网页设计能够提供一致的用户体验,提升网站的可访问性和可用性,同时也有助于搜索引擎优化(SEO),因为搜索引擎更倾向于推荐适应各种设备的网站。

Response: “Responsive web design is an approach to web development that ensures a website’s layout and functionality adapt to different devices and screen sizes. This is achieved through the use of fluid grids, flexible images, and CSS media queries. Responsive design is crucial in modern web development because it provides a seamless user experience across various devices, improving accessibility and reducing the need for separate mobile websites or applications.”
响应式网页设计是一种网页开发方法,确保网站的布局和功能能够适应不同的设备和屏幕尺寸。这是通过使用流体网格、灵活的图像和 CSS 媒体查询来实现的。响应式设计在现代网页开发中至关重要,因为它提供了跨各种设备的无缝用户体验,提高了可访问性,并减少了对单独移动网站或应用程序的需求。

5.4 Handling ambiguous or contradictory user inputs
5.4 处理模糊或矛盾的用户输入

ChatGPT may occasionally receive ambiguous or contradictory inputs. In such cases, you can design prompts that encourage clarification or provide multiple interpretations.
ChatGPT 可能偶尔会收到模糊或矛盾的输入。在这种情况下,您可以设计提示以鼓励澄清或提供多种解释。

Example: 示例:

Ambiguous Prompt: “How long does it take to charge?”
模糊提示:“充电需要多长时间?”

Clarifying Response: “Your question is ambiguous. Please specify the device or object you are referring to, and I will provide the charging time.”
澄清回复:“您的问题不明确。请具体说明您指的是哪个设备或物体,我将提供充电时间。”

Contradictory Prompt: “What is the best way to lose weight: a high-fat diet or a high-carb diet?”
矛盾的提示:“减肥的最佳方法是什么:高脂饮食还是高碳水化合物饮食?”
Multiple Interpretations Response: “There is no one-size-fits-all answer to this question, as the best diet for weight loss depends on an individual’s specific needs, preferences, and goals. Some people may find success with a high-fat, low-carb diet like the ketogenic diet, while others may benefit from a high-carb, low-fat diet, such as a plant-based diet. It’s important to consult a healthcare professional or nutritionist to determine the most suitable approach for your unique circumstances.”
多重解读回应:“这个问题没有统一的答案,因为最佳的减肥饮食取决于个人的具体需求、偏好和目标。有些人可能会在高脂肪、低碳水化合物的饮食(如生酮饮食)中取得成功,而另一些人可能会从高碳水化合物、低脂肪的饮食(如植物性饮食)中受益。咨询医疗专业人士或营养师,以确定最适合您独特情况的方法是很重要的。”

6 Case Studies: Real-World Applications of Prompt Engineering
6 个案例研究:提示工程的实际应用

In this section, we explore various real-world applications of prompt engineering to demonstrate how these techniques can enhance ChatGPT’s performance across diverse domains.
在本节中,我们探讨了提示工程的各种现实应用,以展示这些技术如何提升 ChatGPT 在不同领域的表现。

6.1 Customer support chatbots
6.1 客户支持聊天机器人

ChatGPT can be used to create customer support chatbots capable of addressing user queries effectively. By crafting precise prompts and leveraging context, you can ensure that the chatbot provides relevant and accurate responses.
ChatGPT 可以用来创建能够有效解决用户查询的客户支持聊天机器人。通过精确设计提示和利用上下文,您可以确保聊天机器人提供相关和准确的回复。

Example: 示例:

Prompt: “As a customer support chatbot, explain how to reset a user’s password.”
作为客户支持聊天机器人,解释如何重置用户的密码。

Response: "To reset a user’s password, please follow these steps:
要重置用户的密码,请按照以下步骤操作:
  1. Go to the account login page.
    前往账户登录页面。
  2. Click on the ‘Forgot Password’ link.
    点击“忘记密码”链接。
  3. Enter the user’s registered email address.
    输入用户注册的电子邮件地址。
  4. Click ‘Submit’ to send a password reset link to the user’s email.
    点击“提交”以将密码重置链接发送到用户的电子邮件。
  5. Ask the user to check their email and click on the link provided.
    请用户检查他们的电子邮件并点击提供的链接。
  6. They will be redirected to a password reset page, where they can create a new password.
    他们将被重定向到密码重置页面,在那里可以创建新密码。
  7. Once the new password is set, instruct the user to log log log\log in using their new credentials."
    一旦新密码设置完成,请指导用户 log log log\log 使用他们的新凭据。

6.2 Content generation and editing
6.2 内容生成与编辑

ChatGPT can generate and edit content for various purposes, such as blog posts, social media updates, or product descriptions. By providing clear instructions and desired outcomes, you can achieve higher-quality output.
ChatGPT 可以生成和编辑各种目的的内容,例如博客文章、社交媒体更新或产品描述。通过提供清晰的指示和期望的结果,您可以获得更高质量的输出。

Example: 示例:

Prompt: “Write a short and engaging introduction for a blog post about the benefits of meditation.”
撰写一篇关于冥想好处的博客文章的简短而引人入胜的介绍。

Response: “In today’s fast-paced world, finding inner peace and tranquility can seem like an elusive goal. But what if there was a simple, time-tested practice to help you unlock the door to mental clarity and emotional balance? Enter the world of meditation - a powerful tool that can transform your life, one mindful breath at a time. Read on to discover the remarkable benefits of this ancient practice and learn how it can help you cultivate a calmer, more focused mind.”
回应:“在当今快节奏的世界中,寻找内心的平静与宁静似乎是一个难以实现的目标。但如果有一种简单、经过时间考验的练习可以帮助你打开通往心理清晰和情感平衡的大门呢?进入冥想的世界——一种强大的工具,可以让你的生活发生改变,一次专注的呼吸。继续阅读,发现这种古老练习的显著好处,并了解它如何帮助你培养一个更平静、更专注的心灵。”

6.3 Domain-specific knowledge retrieval
6.3 领域特定知识检索

ChatGPT can be used to answer domain-specific questions or provide specialized advice by refining prompts for better context.
ChatGPT 可以通过优化提示以获得更好的上下文,来回答特定领域的问题或提供专业建议。

Example: 示例:

Prompt: “As a gardening expert, what are some easy-to-grow plants for beginners?”
作为园艺专家,初学者有哪些容易种植的植物?

Response: "For beginners looking to start gardening, I recommend the following easy-to-grow plants:
对于想要开始园艺的初学者,我推荐以下易于种植的植物:
  1. Marigolds: These vibrant flowers are low-maintenance and thrive in a variety of soil types.
    金盏菊:这些色彩鲜艳的花朵易于养护,适应多种土壤类型。
  2. Basil: This popular herb grows quickly and can be used in a wide range of dishes.
    罗勒:这种受欢迎的草药生长迅速,可以用于多种菜肴。
  3. Tomatoes: Choose a hardy variety like cherry tomatoes for a bountiful harvest.
    番茄:选择像樱桃番茄这样的耐寒品种,以获得丰收。
  4. Zucchini: These fast-growing vegetables are perfect for garden beds or containers.
    西葫芦:这些生长迅速的蔬菜非常适合花园床或容器种植。
  5. Sunflowers: With their cheerful appearance, sunflowers are easy to grow and require minimal care.
    向日葵:向日葵以其愉悦的外观而闻名,易于种植且需要的护理很少。
  6. Remember to provide adequate sunlight, water, and well-draining soil for optimal growth."
    记得提供充足的阳光、水分和良好的排水土壤,以促进最佳生长。

6.4 Interactive storytelling and gaming
6.4 互动故事讲述与游戏

ChatGPT can be utilized for interactive storytelling and gaming experiences by creating engaging narratives and responding to user inputs.
ChatGPT 可以用于互动故事讲述和游戏体验,通过创建引人入胜的叙事并响应用户输入。

Example: 示例:

Prompt: “You are an adventurer entering a mysterious cave. Describe the cave and mention a hidden treasure.”
你是一位冒险者,正在进入一个神秘的洞穴。这个洞穴阴暗潮湿,四周布满了奇形怪状的石头,墙壁上闪烁着微弱的荧光。空气中弥漫着一股古老的气息,似乎隐藏着无数秘密。在洞穴的深处,你发现了一处隐秘的宝藏,闪烁着金色的光芒,散发着诱人的气息。

Response: “As you step into the mysterious cave, the cool, damp air envelops you. The faint glow of bioluminescent fungi illuminates the walls, revealing ancient symbols etched into the stone. The cave seems to stretch endlessly, with numerous twisting passageways branching out in every direction. Somewhere deep within this subterranean labyrinth lies a hidden treasure, a legendary artifact said to possess unimaginable power. As you venture further into the darkness, each step echoing through the silent passages, you prepare to face the unknown challenges that await you on your quest to uncover the lost secrets of the cave and claim the fabled treasure as your own.”
回应:“当你走进神秘的洞穴时,凉爽潮湿的空气包围着你。微弱的生物发光真菌照亮了墙壁,显现出刻在石头上的古老符号。洞穴似乎无尽延伸,许多扭曲的通道向四面八方延展。在这个地下迷宫的深处,隐藏着一件传说中的宝物,传说它拥有无法想象的力量。当你进一步深入黑暗中,每一步在寂静的通道中回响时,你准备面对未知的挑战,去揭开洞穴失落的秘密,并将这件传奇宝物据为己有。”

7 Conclusion 7 结论

7.1 The impact of effective prompt engineering on ChatGPT performance
7.1 有效提示工程对 ChatGPT 性能的影响

Effective prompt engineering plays a vital role in enhancing ChatGPT’s performance across various applications, such as customer support chatbots, content generation and editing, domain-specific knowledge retrieval, and interactive storytelling and gaming. By employing the techniques, tips, and best practices outlined in this article, users can obtain more accurate, relevant, and creative results from this powerful AI language model.
有效的提示工程在提升 ChatGPT 在各种应用中的表现方面发挥着至关重要的作用,例如客户支持聊天机器人、内容生成和编辑、特定领域知识检索以及互动故事讲述和游戏。通过采用本文中概述的技术、技巧和最佳实践,用户可以从这个强大的 AI 语言模型中获得更准确、相关和富有创意的结果。

7.2 Future directions in prompt engineering research and applications
7.2 提示工程研究和应用的未来方向

As the field of AI and natural language processing advances, new research and applications will emerge in prompt engineering. Potential areas of exploration include developing more sophisticated prompt strategies, integrating external resources and APIs, and creating interactive, multi-turn conversational systems. These advancements will pave the way for AI language models like ChatGPT to become even more versatile and valuable tools across numerous applications.
随着人工智能和自然语言处理领域的发展,提示工程将出现新的研究和应用。潜在的探索领域包括开发更复杂的提示策略、整合外部资源和 API,以及创建互动的多轮对话系统。这些进展将为像 ChatGPT 这样的 AI 语言模型铺平道路,使其在众多应用中变得更加多功能和有价值。

7.3 Encouraging creativity and collaboration in the ChatGPT community
7.3 鼓励 ChatGPT 社区中的创造力和合作

Fostering creativity and collaboration within the ChatGPT community is crucial for the continuous improvement of prompt engineering best practices. By sharing experiences, innovations, and successes, users can contribute to the ongoing development of the field and inspire new ideas. This collective effort will drive innovation in prompt engineering and help AI language models like ChatGPT reach their full potential.
在 ChatGPT 社区中培养创造力和协作对于持续改进提示工程最佳实践至关重要。通过分享经验、创新和成功,用户可以为该领域的持续发展做出贡献,并激发新想法。这种集体努力将推动提示工程的创新,并帮助像 ChatGPT 这样的 AI 语言模型发挥其全部潜力。

References 参考文献

[1] OpenAI. (2021). ChatGPT: A Generative Pre-trained Transformer for Natural Language Processing. Retrieved from https://www.openai.com/chatgpt/
[1] OpenAI. (2021). ChatGPT:一种用于自然语言处理的生成预训练变换器。来自 https://www.openai.com/chatgpt/ 的资料。
Sabit Ekin received his Ph.D. degree in Electrical and Computer Engineering from Texas A&M University, College Station, TX, USA, in 2012. He has four years of industrial experience as a Senior Modem Systems Engineer at Qualcomm Inc., where he received numerous Qualstar awards for his achievements and contributions to the design of cellular modem receivers. He is currently an Associate Professor of Engineering Technology and Electrical & Computer Engineering at Texas A&M University. Prior to this, he was an Associate Professor of Electrical and Computer Engineering at Oklahoma State University. His research interests include the design and analysis of wireless communication and sensing systems, and applications of artificial intelligence and machine learning.
萨比特·埃金于 2012 年在美国德克萨斯州大学站的德克萨斯农工大学获得电气与计算机工程博士学位。他在高通公司担任高级调制解调器系统工程师,拥有四年的工业经验,在此期间因其在蜂窝调制解调器接收器设计方面的成就和贡献获得了多项 Qualstar 奖项。目前,他是德克萨斯农工大学工程技术及电气与计算机工程的副教授。在此之前,他曾是俄克拉荷马州立大学电气与计算机工程的副教授。他的研究兴趣包括无线通信和传感系统的设计与分析,以及人工智能和机器学习的应用。