提示简介

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

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

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

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 的价值观或政策时,模型可能会拒绝回答并提供后备回答。

在以下几种情况下,模型可能会拒绝回答:

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

特定于任务的指导

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

后续步骤