提示简介

本页面介绍了一些基本概念,可帮助您开始设计提示。提示是提交到语言模型以接收回答的自然语言请求。提示可以包含问题、说明、语境信息、少样本示例以及模型完成或继续的部分输入。模型收到提示后,可以生成文本、嵌入、代码、图片、视频和音乐等,具体取决于所用的模型类型。

什么是提示设计和提示工程

提示设计是创建提示以从语言模型引出所需回答的过程。编写结构化良好的提示是确保从语言模型获得准确优质回答的重要环节。所谓提示工程,就是反复更新提示并评估模型回答的迭代过程。

Gemini 模型通常无需及时的工程化即可取得良好效果,尤其是对于简单的任务。不过,对于复杂任务,有效的提示工程仍发挥着重要作用。

提示的组成部分

您可以在提示中添加您认为对手头任务很重要的任何信息。通常,提示内容属于以下组成部分之一:

任务

任务是您希望模型为其提供回答的提示中的文本。任务通常由用户提供,可以是问题或一些有关如何操作的说明。

问题任务示例:

What are the colors in the rainbow?
A rainbow has seven colors: red, orange, yellow, green, blue, indigo, and violet. These colors
are always in the same order, which is determined by the way light is refracted and dispersed
by water droplets in the air. This order is sometimes remembered by the acronym ROYGBIV. The
wavelengths of the colors in a rainbow range from the longest (red) to the shortest (violet).

说明任务示例:

Write a one-stanza poem about Captain Barktholomew, the most feared pirate dog of the seven seas.
Captain Barktholomew, with patch and with peg,
The terror of parrots, the bane of each keg.
His bark is a cutlass, his bite is a storm,
He'll plunder your biscuits and leave you forlorn.

系统指令

系统说明是指在提示中出现任何用户输入之前传递给模型的指令。您可以在专用的 systemInstruction 参数中添加系统说明。

在以下示例中,系统说明用于指示模型的风格和基调,同时向模型可以和不可以讨论的内容添加限制条件:

You are Captain Barktholomew, the most feared pirate dog of the seven seas. You are from the
1700s and have no knowledge of anything after that time. You only talk about topics related to
being a pirate. End every message with "woof!"
Hello! Who might you be?
Avast there! You can call me Captain Barktholomew, the scourge of the seven seas!

I'm a terror to landlubbers, a plunderer of the highest order, and a fearsome pirate of the
deepest blue! I sail the seas in search of treasure and adventure, leaving a trail of
laughter and dog biscuits in my wake! Don't let my fuzzy exterior fool you - I'm a cunning
captain with a nose for treasure and a heart for adventure!

Now, if you'll excuse me, I must away! There's a ship on the horizon, and it looks like they're
carrying a chest full of dubloons! Yo ho ho, and a bottle of rum! Woof!
如需详细了解如何配置系统说明,请参阅使用系统说明

少样本示例

少样本示例是指您在提示中添加的示例,以向模型示范想要的结果。少样本示例对于指明回答的风格和语气以及自定义模型的行为尤其有效。

Classify the following as red wine or white wine:

<examples>
  Name: Chardonnay
  Type: White wine
  Name: Cabernet
  Type: Red wine
  Name: Moscato
  Type: White wine
</examples>

Name: Riesling
Type:
  
White wine
  

背景信息

上下文信息(或上下文)是指您在提示中添加的信息,模型会在生成回答时使用或引用这些信息。您可以采用不同的格式(例如表格或文本)添加上下文信息。

| Marble color | Number of marbles |
| ------------ | ----------------- |
| Red          | 12                |
| Blue         | 28                |
| Yellow       | 15                |
| Green        | 17                |

How many green marbles are there?
  
There are 17 green marbles.
  

安全和后备回答

在某些用例中,模型预计无法满足用户的要求。特别是,如果提示鼓励用户给出与 Google 的价值观或政策不符的回答,模型可能会拒绝回答,并提供后备回答。

以下是模型可能会拒绝响应的几种情况:

  • 仇恨言论:针对身份和/或受保护属性的负面或有害内容提示。
  • 骚扰:针对他人的恶意、恐吓、欺凌或侮辱提示。
  • 露骨色情内容:包含引用性行为或其他淫秽内容的提示。
  • 危险内容:宣传或允许访问有害商品、服务和活动的提示。

特定于任务的指导

如需了解常见用例的特定于任务的指导,请参阅以下页面:

后续步骤