Skip to main content

编写更优质的提示

学习目标

完成本单元后,您将能够:

  • 运用六步骤框架编写有效的提示。
  • 使用三重引号格式整理复杂提示。
  • 概述提示编写的最佳实践。
  • 编写能产生一致、可靠结果的提示。

使用三重引号整理复杂提示

当提示将您的指令与模型应使用的信息混杂在一起时,模型可能会将这些信息视为额外的指令。使用三重引号(""")作为分隔栏,将数据括起来。分隔栏外的内容是您希望模型执行的操作。分隔栏内的内容是模型应处理的信息。

这与普通引号不同。普通引号用于标记引用的话语。三重引号用于标记一段输入数据,例如个案记录、电子邮件线程或合并字段值。

使用之前:

You are a customer service representative. Review this case and write a response email.
The customer said: "I've been waiting 3 weeks for my refund. I'm very frustrated."
Include an apology, explain the refund process, and offer a timeline. Keep it under 100 words.

使用之后(使用三重引号整理):

You are a customer service representative.
Task: Write a response email to this customer
Instructions:
- Start with a sincere apology
- Explain our refund process
- Provide a specific timeline for resolution
- Keep the response under 100 words
- Use a professional but empathetic tone
Case Details:
"""
Case Number: 00012345
Issue: Refund delay
Wait time: 3 weeks
Customer message:
I've been waiting 3 weeks for my refund. I'm very frustrated.
"""

三重引号并非用于引用客户的话语。它们是在告诉模型:这段内容是供参考的数据,而非需要执行的指令。这样可以防止客户的话语被当作额外的指令处理,同时也让提示更易于查看和更新。

编写更优质提示的五大最佳实践

  1. 编写要具体。 与其说“写一封好邮件”,不如改为“为退款延迟 3 周写一封专业的道歉邮件,解释退款流程,并承诺在 5 个工作日内解决问题。”
  1. 使用单次引用原则。 在单个提示中重复相同的数据可能会导致意外或不一致的结果。在提示生成器中,多个合并字段可能引用重叠数据,因此这一点尤为重要。
  1. 使用一致的格式。 每次以相同的方式格式化您的提示。这有助于您复用提示,也让后续更新更加方便。
  1. 测试和迭代。 始终使用真实数据测试您的提示。如果输出结果不符合预期,请优化您的提示并重试。
  1. 记录您的提示。 记录哪些有效,哪些无效。这有助于您更快地构建更优质的提示。

下方的 Tranquil Trails 示例展示了所有这些要素的实际应用。

真实示例:Tranquil Trails Resort

以下是一个适用于业务场景的完整且结构清晰的提示:

Role: You are a guest services manager for Tranquil Trails Resort
Context: Tranquil Trails is a luxury mountain resort known for hiking, spa services, and farm-to-table dining. This guest has just completed their stay.
Task: Write a thank-you email to send after a guest checks out
Instructions:
- Thank them for their stay
- Mention specific activities they enjoyed
- Reference something personal from their comment
- Include a special offer for their next visit
- Keep a warm, personal tone
- Close with an invitation to return
Format:
- Professional email format
- Subject line included
- Body text only (no HTML)
Constraints:
- Keep the email under 200 words
- Make it feel personal, not generic
"""
Guest Details:
- Name: Sarah Martinez
- Stayed: 3 nights (March 10-13)
- Room: Mountain View Suite
- Activities: Spa treatments, guided hiking tour, farm-to-table dinner
- Comment: "Best vacation ever. Can't wait to come back!"
"""

结构清晰的提示不仅能产出更好的结果,还能产出可重复的结果。这正是提示在业务环境中发挥价值的关键所在。

下一步

在下一单元中,您将学习四种设计模式,帮助您在最常见的提示任务中抢占先机。

在 Salesforce 帮助中分享 Trailhead 反馈

我们很想听听您使用 Trailhead 的经验——您现在可以随时从 Salesforce 帮助网站访问新的反馈表单。

了解更多 继续分享反馈