学习提示词工程

去年 11 月 8 日,新加坡政府科技局(GovTech)组织举办了首届 GPT-4 提示工程(Prompt Engineering)竞赛。数据科学家 Sheila Teo 最终夺冠,成为最终的提示女王(Prompt Queen)。之后,Teo 发布了一篇题为《我如何赢得了新加坡 GPT-4 提示工程赛》的博客文章,慷慨分享了其获胜法门。那么我们直入主题看看她是怎么写提示词的。

图片

1. [🔵] 使用 CO-STAR 框架来搭建 prompt 的结构

    为了让 LLM 给出最优响应,为 prompt 设置有效的结构至关重要。CO-STAR 框架是一种可以方便用于设计 prompt 结构的模板,这是新加坡政府科技局的数据科学与 AI 团队的创意成果。该模板考虑了会影响 LLM 响应的有效性和相关性的方方面面,从而有助于得到更优的响应。

图片

CO-STAR 框架

其工作方式为:

  • (C) 上下文(Context):提供与任务有关的背景信息。这有助于 LLM 理解正在讨论的具体场景,从而确保其响应是相关的。

  • (O) 目标(Objective):定义你希望 LLM 执行的任务。明晰目标有助于 LLM 将自己响应重点放在完成具体任务上。

  • (S) 风格(Style):指定你希望 LLM 使用的写作风格。这可能是一位具体名人的写作风格,也可以是某种职业专家(比如商业分析师或 CEO)的风格。这能引导 LLM 使用符合你需求的方式和词语给出响应。

  • (T) 语气(Tone):设定响应的态度。这能确保 LLM 的响应符合所需的情感或情绪上下文,比如正式、幽默、善解人意等。

  • (A) 受众(Audience):确定响应的目标受众。针对具体受众(比如领域专家、初学者、孩童)定制 LLM 的响应,确保其在你所需的上下文中是适当的和可被理解的。

  • (R) 响应(Response):提供响应的格式。这能确保 LLM 输出你的下游任务所需的格式,比如列表、JSON、专业报告等。对于大多数通过程序化方法将 LLM 响应用于下游任务的 LLM 应用而言,理想的输出格式是 JSON。

CO-STAR 的一个实际应用

这里通过一个实际案例说明 CO-STAR 为什么有用。假设你是一位社交媒体管理者,你需要帮助草拟一篇 Facebook 帖文,其內容是宣传你公司的新产品。

如果不使用 CO-STAR,那么你可能会使用这样的 prompt:

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.

GPT-4 的输出如下:

Introducing the Revolutionary Beta Hairdryer by Alpha!

- Say goodbye to long, tedious hair drying sessions! Alpha is proud to unveil the Beta, our latest innovation in haircare technology.

- 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!

Shop Now: [Link to product page]

这个结果也许够用了,但却只是泛泛而谈,缺乏具体的细节和有针对性的吸引力,而这些是吸引目标受众所必需的。

那如果使用 CO-STAR 模板呢?CO-STAR 会提醒你将任务涉及的其它方面也整合进 prompt 之中,具体来说就是上面的简单 prompt 中缺失的 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.

# OBJECTIVE #

Create a Facebook post for me, which aims to get people to click on the product link to purchase it.

# 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.

# RESPONSE #

The Facebook post, kept concise yet impactful.

通过使用 CO-STAR,GPT-4 的响应会变得明显更有针对性、效果更好:

Embrace Effortless Elegance with Alpha Beta — The Ultra-Fast Hairdryer for the Wise Generation.

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 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.

Make every day a good hair day with Alpha Beta. Experience the blend of sophistication and simplicity today.

[Your Product Link Here]

CO-STAR 框架能引导用户以一种结构化的方式向 LLM 提供有关你的任务所有关键信息,从而确保得到完全符合你的需求的定制化的更优的响应。

END 未完待续

本文素材来源网络,如有侵权请联系删除

👇点击关注AI疯人院公众号获取

更多技术信息~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT大头

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值