撰寫更有效率的提示

已完成

Azure OpenAI 模型能夠產生精確度顯著的自然語言查詢回應。 不過,回應的品質很大程度上取決於提示撰寫的如何。 開發人員可以在提示中使用不同技術來最佳化 Azure OpenAI 模型的效能,進而產生更精確的相關回應。

提供明確的指示

向 Azure OpenAI 模型提出明確要求是取得所需結果的方式之一。 盡可能提供描述,模型就能產生最符合您正在尋找的回應。

例如,假設您想要建立新水瓶的產品描述。 請考慮建立與每個提示關聯的回答:

提示

Write a product description for a new water bottle

回應

Introducing the latest addition to our product line - the innovative and eco-friendly water bottle.
Made from high-quality, BPA-free materials, this bottle is designed to keep your beverages at the
perfect temperature for hours. Its sleek and stylish design makes it the perfect accessory for any
outdoor activity or workout session. With its convenient carrying handle and leak-proof lid, you 
can take it with you wherever you go, without worrying about spills or leaks. Plus, its easy-to-clean
design ensures that you can use it again and again, making it the perfect choice for anyone looking 
for a reliable and sustainable water bottle.

與類似提示相比,具有明確的指示。

提示

Write a product description for a new water bottle that is 100% recycled. Be sure to include that
it comes in natural colors with no dyes, and each purchase removes 10 pounds of plastic from our 
oceans

回應

Introducing our newest water bottle, the eco-friendly choice for the conscious consumer. Made from 
100% recycled materials and available in natural colors with no dyes, this bottle is not only 
stylish but also sustainable. Each purchase of this bottle removes 10 pounds of plastic from 
our oceans, making it a responsible choice for those who care about the environment. Its durable 
and leak-proof design makes it perfect for outdoor activities, while its easy-to-carry handle 
makes it convenient to take on the go. Join us in our mission to reduce plastic waste and choose 
this eco-friendly water bottle for your daily hydration needs.

包括需要包含的特定內容,可讓模型知道要新增至描述的資訊,從而更精確地描述新產品。

這個方法可以被推斷為包含複雜的指示,例如要包含的詳細資料項目符號清單、回應長度,或輸出中要包含的所需格式。 請嘗試確切要求您想在結果中看到的內容,您可能會對模型滿足您要求的程度感到驚訝。

指示的格式

格式化指示的方式可能會影響模型解譯提示的方式。 近因偏差可能會影響模型,其中位於提示結尾的資訊對輸出產生的影響,可能會比位於開頭的資訊更大。 您可以重複提示結尾的指示,並評定這對產生的回應有何影響,以取得更好的回應。

在聊天案例中使用 ChatCompletion 時,此近因偏差也會生效,其中提示包含交談中較新的訊息會對回應產生顯著的影響。 下一個單元會更深入了解如何使用交談來改善回應品質,不過將重要資訊放在更接近提示結尾,回應的效果可能會更好。

使用區段標記

格式化指示的特定技術是分割提示開頭或結尾的指示,並讓使用者內容包含在 ---### 區塊內。 這些標記可讓模型更明確地區分指示和內容。 例如:

Translate the text into French

---
What's the weather going to be like today?
---

注意

區段標記的最佳做法可能會隨著之後的版本而變更。

主要、支援和基礎內容

包括模型用來回應的內容,使其能提供更精確的回答。 可以透過兩種方式來考慮內容:主要和支援內容。

主要內容是指查詢主體的內容,例如要翻譯的句子或要摘要的文章。 這個內容通常包含在提示的開頭或結尾 (作為指示且以 --- 區塊區分),提供說明其用途的指示。

例如,假設我們有一篇想進行摘要的長文章。 我們可以將其放在提示中的 --- 區塊中,然後以指示作為結尾。

---
<insert full article here, as primary content>
---

Summarize this article and identify three takeaways in a bulleted list

支援內容是可能會改變回應的內容,但不是提示的重點或主旨。 支援內容的範例包括名稱、偏好、回應中要包含的未來日期等等。 提供支援內容可讓模型做出更完整且更精確的回應,並且更有可能包含所需的資訊。

例如,假設有一封內容很長的促銷電子郵件,模型就能夠擷取重點資訊。 接著,如果您想在提示中新增支援內容,指定您正在尋找的特定內容,則模型可以提供更實用的回應。 在此案例中,電子郵件是主要內容,而您感興趣的是支援內容中的特定內容

---
<insert full email here, as primary content>
---
<the next line is the supporting content>
Topics I'm very interested in: AI, webinar dates, submission deadlines

Extract the key points from the above email, and put them in a bulleted list:

基礎內容為模型提供內容,使其從中獲取回答,以便讓模型能夠提供可靠的回答。 基礎內容可能是您隨後據以提出問題的短文或文章、公司常見問題集文件,或比模型定型資料更近期的資訊。 如果您需要更可靠的最新回應,或需要參考未發佈或特定資訊,強烈建議使用基礎內容。

基礎內容與主要內容不同,因為它是回答提示查詢的資訊來源,而不是用於摘要或翻譯等操作的內容。 例如,提供一篇未發佈的 AI 歷程記錄研究論文時,就可以使用該基礎內容來回答問題。

---
<insert unpublished paper on the history of AI here, as grounding content>
---

Where and when did the field of AI start?

此基礎資料可讓模型提供更精確且更有依據的回答,但其可能不屬於定型的資料集。

提示

提示是建置模型的前置詞,通常有助於以正確的方向塑造回應。 它們通常與指示搭配使用,但並非總是如此。 針對程式碼產生提示 (Prompting) 模型時,提示 (Cue) 特別實用。 目前的 Azure OpenAI 模型可以產生一些有趣的程式碼片段,不過之後的課程模組中將更深入討論程式碼產生。

例如,如果您想要協助建立 SQL 查詢,請提供您需要的指示以及查詢的開頭:

Write a join query to get customer names with purchases in the past 30 days between tables named orders and customer on customer ID. 

SELECT

即使我們從未要求使用特定語言,模型回應仍會從離開的提示位置繼續使用 SQL。 其他範例可能是透過提供所需應用程式的程式碼註解,並在提示結尾包含作為前置詞的 import,或類似的所需語言,來協助使用 Python 程式碼。

另一個範例是,在提示中提供大量的客戶評論集合,並以其作為結尾:

Summarize the reviews above:
Most common complaints:
- 

接著,模型會知道如何根據評論中提供的內容來完成陳述式。