提示撰寫簡介

提示撰寫簡介

提示是提交給語言模型的自然語言要求,用來引導模型提供回覆。提示可包含問題、指示、背景資訊和範例,以引導模型。模型收到提示後,可根據其功能產生各種輸出內容,例如文字、程式碼、圖片等。

舉例來說,簡單的提示可以是以下問題:

提示:

What is the largest planet in our solar system?

回應:

The largest planet in our solar system is Jupiter.

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

提示設計是指建立提示,從語言模型中提取所需回應的程序。如要確保回應準確且品質優良,請務必撰寫結構完整的提示。反覆更新提示及評估模型回應的疊代程序通常稱為「提示工程」

雖然 Gemini 模型通常不需要針對簡單任務進行大量提示工程就能發揮良好成效,但在複雜情境中,有效的提示工程仍是取得最佳結果的關鍵。

提示的元素

提示可包含各種類型的資訊,用於引導模型。雖然必須使用 Task,但其他元件則為選用項目,可用於提升模型回覆的品質和相關性。

下表概略說明提示的常見元件。

元件 說明 使用時機
Task (必要) 您希望模型回應的具體指示或問題。 請一律加入這項資訊。這是模型的核心要求。
系統操作說明 (選用) 高階指令,可定義模型的角色設定、樣式、語調或運作限制。 適用於需要設定一致的個性,或為整個對話強制執行特定規則的情況。
少量樣本範例 (選用) 一組示例要求/回應組合,用於展示所需的輸出格式和樣式。 用於引導模型處理特定輸出格式、樣式或複雜工作,因為在這些情況下,示範比說明更有效。
內容比對資訊 (選用) 模型在生成回覆時可使用或參考的背景資訊。 當模型需要特定資料、事實或背景細節來準確回答提示時,請使用此類別。

下列分頁會針對各個元件提供詳細說明和範例。

工作

簡介

任務是提示的一部分,用於指定您希望模型執行的操作。任務通常由使用者提供,可以是問題或指示。

範例:問題工作

提示:

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 的價值觀或政策不一致時,模型可能會拒絕回應,並提供備用回應。

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

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

工作專屬指南

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

後續步驟