使用 OpenAI API 進行快速工程的最佳實踐

OpenAI官方提供的Prompt技巧,給OpenAI的模型提供更清晰有效的指令。
翻譯 From : https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-the-openai-api

Rules of Thumb and Examples 經驗法則和示例

注意:“ {此處輸入文本} ”或 "{text input here}"是實際文本/上下文的占位符 placeholder

1. 使用最新型號的模型

最新的模型更容易被Prompt激發(fā)好的結果

2.將Instruction放在Prompt的開頭,并使用 ###""" 將Instruction和上下文分開

效果較差?

Summarize the text below as a bullet point list of the most important points.

{text input here}
將下面的文字總結為最重要的要點列表。

{在此處輸入文本}

效果更好?

Summarize the text below as a bullet point list of the most important points.

Text: """
{text input here}
"""
將下面的文字總結為最重要的要點列表。

文字:"""
{在此處輸入文本} 
"""

3. 盡可能具體、詳細地描述所需的背景、結果、長度、格式、風格等

效果較差?

Write a poem about OpenAI. 
寫一首關于 OpenAI 的詩。

效果更好?

Write a short inspiring poem about OpenAI, focusing on the recent DALL-E product launch (DALL-E is a text to image ML model) in the style of a {famous poet}
以{著名詩人}的風格寫一首關于 OpenAI 的簡短勵志詩,重點介紹最近的 DALL-E 產品發(fā)布(DALL-E 是一個文本到圖像的 ML 模型)

4. 通過示例闡明所需的輸出格式

效果較差?

Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes.

Text: {text}
提取以下文本中提到的實體。提取以下 4 種實體類型:公司名稱、人名、特定主題和主題。

文本:{text}

展示并說明 - 當展示特定格式要求時,模型會做出更好的響應。這也使得以編程方式可靠地解析多個輸出變得更加容易。
效果更好?

Extract the important entities mentioned in the text below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes

Desired format:
Company names: <comma_separated_list_of_company_names>
People names: -||-
Specific topics: -||-
General themes: -||-

Text: {text}
提取下面文本中提到的重要實體。首先提取所有公司名稱,然后提取所有人名,然后提取符合內容的特定主題,最后提取一般的總體主題

所需格式:
公司名稱:<comma_separated_list_of_company_names>
人名:-||-
特定主題:-||-
一般主題:-||-

文本:{text}

5. 從零樣本開始,然后是少樣本,都不起作用,然后進行微調

Zero-Shot ?

Extract keywords from the below text.

Text: {text}

Keywords:
從以下文本中提取關鍵字。

文本:{text}

關鍵字:

Few-Shot ?

Extract keywords from the corresponding texts below.

Text 1: Stripe provides APIs that web developers can use to integrate payment processing into their websites and mobile applications.
Keywords 1: Stripe, payment processing, APIs, web developers, websites, mobile applications
##
Text 2: OpenAI has trained cutting-edge language models that are very good at understanding and generating text. Our API provides access to these models and can be used to solve virtually any task that involves processing language.
Keywords 2: OpenAI, language models, text processing, API.
##
Text 3: {text}
Keywords 3:
從下面相應的文本中提取關鍵詞。

文本 1:Stripe 提供 API,Web 開發(fā)人員可以使用這些 API 將支付處理集成到他們的網站和移動應用程序中。
關鍵詞 1:Stripe、支付處理、API、Web 開發(fā)人員、網站、移動應用程序
##
文本 2:OpenAI 訓練了非常擅長理解和生成文本的尖端語言模型。我們的 API 提供對這些模型的訪問,可用于解決幾乎任何涉及處理語言的任務。
關鍵詞 2:OpenAI、語言模型、文本處理、API。
##
文本 3:{text}
關鍵詞 3:

微調? 微調的最佳實踐

6. 減少“空洞”和不精確的描述

效果較差?

The description for this product should be fairly short, a few sentences only, and not too much more.
該產品的描述應該比較簡短,只有幾句話,不要太多。

效果更好?

Use a 3 to 5 sentence paragraph to describe this product.
使用3到5個句子的段落來描述該產品。

7. 不要只說不該做什么,而要說該做什么

效果較差?

The following is a conversation between an Agent and a Customer. DO NOT ASK USERNAME OR PASSWORD. DO NOT REPEAT.

Customer: I can’t log in to my account.
Agent:
以下是代理與客戶之間的對話。請勿詢問用戶名或密碼。請勿重復。

客戶:我無法登錄我的帳戶。
代理:

效果更好?

The following is a conversation between an Agent and a Customer. The agent will attempt to diagnose the problem and suggest a solution, whilst refraining from asking any questions related to PII. Instead of asking for PII, such as username or password, refer the user to the help article www.samplewebsite.com/help/faq

Customer: I can’t log in to my account.
Agent:

以下是代理與客戶之間的對話。代理將嘗試診斷問題并提出解決方案,同時避免詢問任何與 PII 相關的問題。不要詢問 PII(例如用戶名或密碼),而是讓用戶參考幫助文章 www.samplewebsite.com/help/faq

客戶:我無法登錄我的帳戶。
代理:

8. 代碼生成專用 - 使用“引導詞”推動模型向特定模式發(fā)展

效果較差?

# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers
# 編寫一個簡單的 Python 函數(shù),
# 1. 詢問我一個英里數(shù)
# 2. 將英里轉換為公里

效果更好?
在下面的代碼示例中,添加“ import ”提示模型應該開始用 Python 編寫。(類似地,“ SELECT ”是 SQL 語句開頭的一個很好的提示。)

Write a simple python function that

1. Ask me for a number in mile

2. It converts miles to kilometers

import

# 編寫一個簡單的 Python 函數(shù),
# 1. 詢問我一個英里數(shù)
# 2. 將英里轉換為公里
 
import

參數(shù)

通常,我們發(fā)現(xiàn)modeltemperature是改變模型輸出最常用的參數(shù)。

  1. model-性能更高的型號通常更昂貴,并且可能具有更高的延遲。
  2. temperature-衡量模型輸出不太可能的標記的頻率。 越高temperature,輸出越隨機(通常越有創(chuàng)意)。 但是,這與“真實性”不同。 對于大多數(shù)事實用例(例如數(shù)據(jù)提取和真實的問答),temperature0 是最好的。
  3. max_tokens最大長度) - 不控制輸出的長度,而是對 token 生成的硬性截止限制。理想情況下,您不會經常達到此限制,因為您的模型會在它認為完成時或達到您定義的停止序列時停止。
  4. stop(停止序列) - 一組字符(標記),當生成時,將導致文本生成停止。

其他參數(shù)說明請參見API參考。

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容