生成式 AI 的提示工程

提示工程的秘訣,是先提出適當的問題 表現最佳的 LLM透過以下方式與 LLM 直接互動 只有純文字提示

在過去,要運用機器學習模型,通常需要深厚的知識才能勝任。 具備資料集、統計資料和建模技術的知識。現在 LLM 「編程」以及英文 其他語言

要成為優秀的提示工程師,不需要具備程式設計經驗也能輕鬆上手。創意 不過,持續存取模式將對你的學習過程造成很大的幫助。繼續閱讀 學習一些實用的提示技巧

提示最佳做法

  1. 清楚傳達出最重要的內容或資訊。

  2. 建立提示結構:先定義角色、提供背景資訊/輸入資料 然後提供指示

  3. 使用各種具體範例,協助模型縮小焦點並生成 提供更準確的結果

  4. 運用限制條件來限制模型輸出內容的範圍。這有助於避免 忽略指示為事實提供錯誤。

  5. 將複雜工作拆成一連串的簡單提示。

  6. 指示模型先評估或檢查自己的回應,再生成 具體做法是指示 Kubernetes 建立並維護 一或多個代表這些 Pod 的物件(「務必將回覆內容限縮為 3 句」、「為工作評分」 為精簡扼要,請以 1 到 10 表示:「你覺得這正確嗎?」。

更重要的是:

發揮創意!創意越多越好 保持心態,研究結果越出色LLM 和提示 但工程領域仍處於起步階段,且日新月異。

提示類型

直接提示 (零樣本)

「直接提示」(又稱為「零樣本」) 是最簡單的提示類型。這項服務 沒有為模型提供任何範例,只有指令。你也可以使用 或輸入「角色」給模型如第二個步驟所示 範例。

請提供:

  1. 操作說明
  2. 部分背景資訊

構思點子:

Prompt: Can you give me a list of ideas for blog posts for tourists visiting
New York City for the first time?

角色提示:

Prompt: You are a mighty and powerful prompt-generating robot. You need to
understand my goals and objectives and then design a prompt. The prompt should
include all the relevant information context and data that was provided to you.
You must continue asking questions until you are confident that you can produce
the best prompt for the best outcome. Your final prompt must be optimized for
chat interactions. Start by asking me to describe my goal, then continue with
follow-up questions to design the best prompt.

資料整理:

Prompt: Create a four-column spreadsheet of 10 highly-rated science fiction
movies, year of release, average audience rating, and top 3 keywords from
audience reviews.

Make sure to cite the source of the audience rating.

使用範例提示 (單樣本、少量和多樣本)

單樣本提示讓模型清楚呈現內容 實際生成的文字

以單一範例構思創意:

Prompt:

Come up with a list of ideas for blog posts for tourists visiting
New York City for the first time.

1. Fuggedaboutit! Where to Stay in New York City On Your First Visit

少量樣本和多樣本提示為模型提供更多符合需求的樣本 該如何採取行動比起零樣本,處理較複雜的工作會比較好,而且能依照模式 或當您需要將輸出內容建構成 難以描述

少量樣本情緒分類:

Prompt:

Great product, 10/10: Positive
Didn't work very well: Negative
Super helpful, worth it: Positive
It doesn't work!:

執行這項提示時,模型的回應會歸類為 公司視為正面或負面,如示例所示。

多樣本表情符號回應預測工具:

Prompt: Predict up to 5 emojis as a response to a text chat message. The output
should only include emojis.

input: The new visual design is blowing my mind 🤯
output: ➕,💘, ❤‍🔥

input: Well that looks great regardless
output: ❤️,🪄

input: Unfortunately this won't work
output: 💔,😔

input: sounds good, I'll look into that
output: 🙏,👍

input: 10hr cut of jeff goldblum laughing URL
output: 😂,💀,⚰️

input: Woo! Launch time!

這裡的流程相同,但由於提示內容比較複雜,因此模型已 提供更多模擬範例

思維鏈提示

思維鏈 (CoT) 提示會鼓勵 LLM 說明推論。 結合使用少量樣本提示,針對較複雜的工作取得更出色的成果 提供回應

Prompt:

The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.
A: Adding all the odd numbers (9, 15, 1) gives 25. The answer is False.
The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.
A:

零樣本 CoT

回想先前說的零樣本提示,這種做法 提示,並加入指示:「我們會逐步思考。」LLM 能 根據此指示生成一系列的想法,且通常更加準確 自動生成最佳解答這是讓 LLM 生成正確內容 提供應用題解答等問題

Prompt:

I went to the market and bought 10 apples. I gave 2 apples to the neighbor and
2 to the repairman. I then went and bought 5 more apples and ate 1. How many
apples was I left with?

Let's think step by step.

提示疊代策略

數十個 (也許是數十個) 次。如果遇到問題,可以參考以下幾個調整提示:

注意:隨著時間的推移,這些策略的實用性或需求可能會隨時間增加。 改善模型

  1. 重複關鍵字、詞組或提案

  2. 指定所需的輸出格式 (CSV、JSON 等)

  3. 請使用全部大寫來壓力重要要點或指示。你也可以試試 誇張或誇大的用語;例如:「您的說明 因此很容易遭到誤解每個字的意思都必須清晰無比!」

  4. 使用同義詞或替代語句 (例如,不要使用「總結」,而是改用「總結」), 附加「tldr」不只能輸入文字替換不同的字詞或詞組, 記錄哪些部分成效較佳,哪些情況則較差。

  5. 運用較長的提示,試試三明治技巧:在 不同的位置

  6. 從提示庫汲取靈感。提示主頁 以及這個提示庫 可以先從兩個位置著手

其他資源

提示最佳做法

瞭解提示 (外部)