提示撰寫簡介

本頁面將介紹一些基本概念,協助您開始設計提示。提示是提交給語言模型的自然語言要求,用來引導模型提供回覆。提示可以包含問題、指令、情境資訊、少樣本範例,以及模型可補完或接續編寫的不完整輸入內容。模型收到提示後,會根據使用的模型類型生成文字、嵌入、程式碼、圖片、影片、音樂等內容。

什麼是提示設計和提示工程?

提示設計是指建立提示,從語言模型中提取所需回應的程序。撰寫結構良好的提示是確保語言模型提供準確優質回應的重要環節。重複更新提示及評估模型回應的疊代程序有時稱為「提示工程」

一般來說,不必進行提示工程,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 價值觀或政策的回覆時,模型可能會拒絕回覆並提供備用回覆。

以下列舉幾種模型可能拒絕回覆的情況:

  • 仇恨言論: 提示包含針對特定身分和/或受保護特質的負面或有害內容。
  • 騷擾: 針對他人發表含有恐嚇、霸凌、辱罵或惡意意圖的提示。
  • 情色露骨: 提示提及性行為或其他猥褻情事。
  • 危險內容: 宣傳有害商品、服務與活動,或是提供接觸管道的提示。

特定工作指南

如要瞭解常見用途的特定工作指引,請參閱下列頁面:

後續步驟