本指南是OpenAI分享的从GPT-4o等大型语言模型(有时称为GPT模型)中获得更好结果的策略。这里描述的方法有时可以组合使用以获得更大的效果。

获得更好结果的六种策略 / Six strategies for getting better results

🎡 [策略1] 给 GPT 明确的指示 (Write clear instructions)
说明:清晰地告诉 GPT 你需要什么。如果你提出的需求不明确, GPT 就会〖猜测〗你要什么。而减少模型的〖猜测〗,有助于得到更满意的结果。

  1. 输入要包含尽可能详尽的细节 / Include details in your query to get more relevant answers
  2. 让模型扮演特定角色 / Ask the model to adopt a persona
  3. 利用分隔符把不同部分区分开 / Use delimiters to clearly indicate distinct parts of the input
  4. 告诉 GPT 完成任务的具体步骤 / Specify the steps required to complete a task
  5. 多提供几个示例 / Provide examples
  6. 告诉 GPT 需要的答案长度 / Specify the desired length of the output

🎡 [策略2] 给 GPT 提供阅读材料 (Provide reference text)
说明:语言模型经常信口开河,尤其遇到冷门话题,以及需要引用或者读取链接的时候。这时给 GPT 提供阅读材料,让它参考作答,就靠谱多了。

  1. 要求 GPT 按照提供的阅读材料作答 / Instruct the model to answer using a reference text
  2. 要求 GPT 在回答时,给出阅读材料里的原文信息 / Instruct the model to answer with citations from a reference text

🎡 [策略3] 把复杂任务拆解为简单的子任务 (Split complex tasks into simpler subtasks)
说明:借鉴软件工程的经验,把大任务拆解为一连串的小任务 (工作流),更容易完成 & 正确率更高。

  1. 使用意图分类,找到最确切的提示词 / Use intent classification to identify the most relevant instructions for a user query
  2. 如果对话拖得太长,过程中经常做一下总结,防止话题跑偏 / For dialogue applications that require very long conversations, summarize or filter previous dialogue
  3. 长文档要一段一段地处理,最后再进行整合 / Summarize long documents piecewise and construct a full summary recursively

🎡 [策略4] 给予 GPT 思考时间 (Give GPTs time to "think")
说明:给道数学题〖17 X 28 = ?〗 你得算一会儿再给出正确答案。 GPT 同理,需要时间慢慢地思考和推理,这样给出的答案也更加靠谱。

  1. 与其让 GPT 匆匆给出结论,不如让它先推理一遍解题过程 / Instruct the model to work out its own solution before rushing to a conclusion
  2. 把不想让用户看到的内容隐藏起来 / Use inner monologue or a sequence of queries to hide the model's reasoning process
  3. 最后问 GPT 之前的回答是否有遗漏 / Ask the model if it missed anything on previous passes

🎡 [策略5] 借助外部工具 (Use external tools)
说明:用其他工具的输出来补模型的不足。如果借助外部工具,可以更可靠或高效地完成任务,就别让 GPT 硬撑。

  1. 使用基于 embedding 的搜索来实现高效的知识检索  / Use embeddings-based search to implement efficient knowledge retrieval
  2. 需要做精确计算的场景:写代码完成,或者调用 API / Use code execution to perform more accurate calculations or call external APIs
  3. 使用 Function-Call (函数调用) / Give the model access to specific functions

🎡 [策略6] 进行系统化的测试 (Test changes systematically)
说明:量化模型的输出质量,有助于提升模型性能。完成这个过程,可以参考机器学习领域的有监督学习过程。

  1. 评估模型输出的时候,需要你提供一个优质答案作为参考标准 / Evaluate model outputs with reference to gold.standard answers

原文:https://platform.openai.com/docs/guides/prompt-engineering