Note:
提示词工程是一门融合了艺术和科学的学科——它既是对技术的理解,也是对创造力和战略思维的理解。本文为对LLMS策略分享内容学习后的整理,尝试抛开网上广泛讨论和记录的传统提示词工程技术,展示通过实验学到的新见解,以及对理解和处理某些技术的不同的一些看法。
目录
本文涵盖以下内容,其中 🔵 指适合初学者的提示技巧,而 🔴 指高级策略:
(O) Objective目标:定义您希望 LLM 执行的任务
3. [🔴] 使用 LLM Guardrails 创建系统提示词
1. [🔵] Structuring Prompts using the CO-STAR framework 使用 CO-STAR 框架构建提示
Effective prompt structuring is crucial for eliciting optimal responses from an LLM. The CO-STAR framework, a brainchild of GovTech Singapore’s Data Science & AI team, is a handy template for structuring prompts. It considers all the key aspects that influence the effectiveness and relevance of an LLM’s response, leading to more optimal responses.
有效的提示结构对于从 LLM 中引出最佳响应至关重要。 CO-STAR 框架是 GovTech Singapore 数据科学与人工智能团队的创意,是构建提示的便捷模板。它考虑了影响 LLM 响应的有效性和相关性的所有关键方面,从而产生更优化的响应。

CO-STAR framework — Image by author
CO-STAR 框架 — 图片由作者提供
Here’s how it works: 它的工作原理如下:
(C) Context: Provide background information on the task
(C) 上下文:提供任务的背景信息
This helps the LLM understand the specific scenario being discussed, ensuring its response is relevant.
这有助于LLM了解正在讨论的具体场景,确保其响应是相关的。
(O) Objective: Define what the task is that you want the LLM to perform
(O) 目标:定义您希望 LLM 执行的任务
Being clear about your objective helps the LLM to focus its response on meeting that specific goal.
明确您的目标有助于LLM将其响应集中在实现该特定目标上。
(S) Style: Specify the writing style you want the LLM to use
(S) 样式:指定您希望 LLM 使用的书写样式
This could be a particular famous person’s style of writing, or a particular expert in a profession, like a business analyst expert or CEO. This guides the LLM to respond with the manner and choice of words aligned with your needs.
这可能是某个特定名人的写作风格,也可能是某个专业的特定专家,例如商业分析师专家或首席执行官。这将指导LLM以符合您需求的方式和词语进行回应。
(T) Tone: Set the attitude of the response
(T) 语气:设定回应的态度
This ensures the LLM’s response resonates with the intended sentiment or emotional context required. Examples are formal, humorous, empathetic, among others.
这可确保 LLM 的响应与所需的预期情绪或情感背景产生共鸣。例子包括正式的、幽默的、善解人意的等等。
(A) Audience: Identify who the response is intended for
(A) 受众:确定响应的目标受众
Tailoring the LLM’s response to an audience, such as experts in a field, beginners, children, and so on, ensures that it is appropriate and understandable in your required context.
针对受众(例如某个领域的专家、初学者、儿童等)定制 LLM 的响应,确保它在您所需的上下文中是适当且易于理解的。
(R) Response: Provide the response format
(R) 响应:提供响应格式
This ensures that the LLM outputs in the exact format that you require for downstream tasks. Examples include a list, a JSON, a professional report, and so on. For most LLM applications which work on the LLM responses programmatically for downstream manipulations, a JSON output format would be ideal.
这可确保 LLM 以下游任务所需的确切格式输出。示例包括列表、JSON、专业报告等。对于大多数以编程方式处理 LLM 响应以进行下游操作的 LLM 应用程序,JSON 输出格式将是理想的选择。
A practical application of CO-STAR
CO-STAR 的实际应用
Here’s a real-world example of why the CO-STAR framework is useful. Let’s say you work as a social media manager, and you need help drafting a Facebook post to advertise your company’s new product.
下面是一个真实示例,说明了 CO-STAR 框架为何有用。假设您是一名社交媒体经理,您需要帮助起草 Facebook 帖子来宣传您公司的新产品。
A quick prompt without CO-STAR might look something like this:
没有 CO-STAR 的快速提示可能如下所示:
Write a facebook post to advertise my company’s new product. My company’s name is Alpha and the product is called Beta, a new ultra-fast hairdryer.
写一篇 Facebook 帖子来宣传我公司的新产品。我公司的名字叫Alpha,产品叫Beta,是一种新型超快速吹风机。
Here’s the output from GPT-4:
这是 GPT-4 的输出:
Introducing the Revolutionary Beta Hairdryer by Alpha!
Alpha 推出革命性的 Beta 吹风机!
- Say goodbye to long, tedious hair drying sessions! Alpha is proud to unveil the Beta, our latest innovation in haircare technology.
- 告别漫长、乏味的吹风过程! Alpha 很自豪地推出 Beta,这是我们在护发技术方面的最新创新。
- Ultra-Fast Drying: The Beta is designed to cut your drying time in half, thanks to its advanced, powerful motor. Get ready faster and enjoy more time doing what you love!
- 超快速吹干:Beta 配备先进、强大的电机,可将吹干时间缩短一半。更快地做好准备,享受更多时间做自己喜欢的事情!
Shop Now: [Link to product page]
立即购买:[产品页面链接]
While adequate, this output is painfully generic, lacking the specific nuances and targeted appeal necessary to resonate with your company’s audience.
虽然足够了,但此输出非常笼统,缺乏引起公司受众共鸣所需的具体细微差别和有针对性的吸引力。
Here’s an example of using the CO-STAR template instead, which reminds you to incorporate other aspects of your task into your prompt, specifically the STYLE, TONE, and AUDIENCE aspects that are missing from the previous quick prompt:
下面是使用 CO-STAR 模板的示例,它提醒您将任务的其他方面合并到提示中,特别是 STYLE 、 TONE 和 AUDIENCE
# CONTEXT # # 语境 #
I want to advertise my company’s new product. My company’s name is Alpha and the product is called Beta, which is a new ultra-fast hairdryer.
我想为我公司的新产品做广告。我公司的名字叫Alpha,产品叫Beta,是一种新型的超快速吹风机。# OBJECTIVE # # 客观的 #
Create a Facebook post for me, which aims to get people to click on the product link to purchase it.
为我创建一个 Facebook 帖子,旨在让人们点击产品链接来购买。# STYLE # # 风格 #
Follow the writing style of successful companies that advertise similar products, such as Dyson.
遵循为类似产品做广告的成功公司(例如戴森)的写作风格。# TONE # # 语气 #
Persuasive 有说服力# AUDIENCE # # 观众 #
My company’s audience profile on Facebook is typically the older generation. Tailor your post to target what this audience typically looks out for in hair products.
我公司在 Facebook 上的受众群体通常是老一代。根据受众通常对护发产品的需求来定制您的帖子。# RESPONSE # # 回复 #
The Facebook post, kept concise yet impactful.
Facebook 上的帖子简洁而富有影响力。
By applying CO-STAR, GPT-4’s response becomes significantly more targeted and effective:
通过应用 CO-STAR,GPT-4 的响应变得更加有针对性和有效:
Embrace Effortless Elegance with Alpha Beta — The Ultra-Fast Hairdryer for the Wise Generation.
Alpha Beta 拥抱轻松优雅——专为明智一代打造的超快速吹风机。Rediscover the joy of simple, effective hair care with Alpha Beta. Our latest innovation is more than just a hairdryer; it’s a promise of swift, gentle, and
使用 Alpha Beta 重新发现简单、有效护发的乐趣。我们最新的创新不仅仅是吹风机;这是一个快速、温柔、和的承诺
reliable hair styling for those who appreciate the finer things in life.
对于那些欣赏生活中美好事物的人来说,可靠的发型设计。- Easy and Intuitive Use: Say goodbye to complicated gadgets. Alpha Beta is
- 简单直观的使用:告别复杂的小工具。阿尔法贝塔是
crafted for comfort and simplicity, perfect for those who value straightforward,
专为舒适和简约而设计,非常适合那些重视简单的人,
hassle-free technology. 无忧技术。
- Time-Saving Technology: We understand your time is precious. That’s why Alpha Beta cuts down drying time significantly, giving you more moments to enjoy life’s pleasures.
- 省时技术:我们了解您的时间非常宝贵。这就是为什么 Alpha Beta 显着缩短干燥时间,让您有更多时间享受生活乐趣。Make every day a good hair day with Alpha Beta. Experience the blend of
使用 Alpha Beta,让每一天都是美好的一天。体验融合
sophistication and simplicity today.
今天的复杂性和简单性。[Your Product Link Here] [您的产品链接在这里]
The CO-STAR framework guides you to provide all of the crucial pieces of information about your task to the LLM in a structured manner, ensuring a tailored and optimized response to exactly what you need.
CO-STAR 框架指导您以结构化方式向 LLM 提供有关您的任务的所有关键信息,确保针对您的需求提供量身定制和优化的响应。
2. [🔵] Sectioning Prompts Using Delimiters使用分隔符进行分段提示

Image generated by DALL·E 3
图像由 DALL·E 3 生成
Delimiters are special tokens that help the LLM distinguish which parts of your prompt it should consider as a single unit of meaning. This is important because your entire prompt arrives to the LLM as a single long sequence of tokens. Delimiters provide structure to this sequence of tokens by fencing specific parts of your prompt to be treated differently.
分隔符是特殊标记,可帮助 LLM 区分提示的哪些部分应视为单个含义单位。这很重要,因为您的整个提示将作为单个长令牌序列到达 LLM。分隔符通过隔离提示的特定部分以进行不同的处理,从而为该标记序列提供结构。
It is noteworthy that delimiters may not make a difference to the quality of an LLM’s response for straightforward tasks. However, the more complex the task, the more impact the usage of delimiters for sectioning has on the LLM’s response.
值得注意的是,分隔符可能不会影响 LLM 对简单任务的响应质量。然而,任务越复杂,使用分隔符进行分段对 LLM 响应的影响就越大。
Delimiters as Special Characters
作为特殊字符的分隔符
A delimiter could be any sequence of special characters that usually wouldn’t appear together, for example:
分隔符可以是通常不会一起出现的特殊字符的任何序列,例如:
- ###
- ===
- >>>
The number and type of special characters chosen is inconsequential, as long as they are unique enough for the LLM to understand them as content separators instead of normal punctuation.
所选择的特殊字符的数量和类型并不重要,只要它们足够独特,让 LLM 将它们理解为内容分隔符而不是正常的标点符号即可。
Here’s an example of how you might use such delimiters in a prompt:
以下是如何在提示中使用此类分隔符的示例:
Classify the sentiment of each conversation in <<<CONVERSATIONS>>> as
将<<<CONVERSATIONS>>>中每个对话的情绪分类为
‘Positive’ or ‘Negative’. Give the sentiment classifications without any other preamble text.
“积极”或“消极”。给出情感分类,无需任何其他序言文本。###
EXAMPLE CONVERSATIONS 对话示例
[Agent]: Good morning, how can I assist you today?
[代理]:早上好,今天需要什么帮助吗?
[Customer]: This product is terrible, nothing like what was advertised!
[顾客]:这个产品太糟糕了,和广告上的完全不一样!
[Customer]: I’m extremely disappointed and expect a full refund.
[顾客]:我非常失望,希望全额退款。[Agent]: Good morning, how can I help you today?
[代理]:早上好,今天有什么可以帮您的吗?
[Customer]: Hi, I just wanted to say that I’m really impressed with your
[顾客]:嗨,我只是想说,我对你们的印象非常深刻
product. It exceeded my expectations!
产品。它超出了我的预期!###
EXAMPLE OUTPUTS 输出示例
Negative 消极的

最低0.47元/天 解锁文章
333

被折叠的 条评论
为什么被折叠?



