提供內容以提高正確性

已完成

藉由提供 AI 模型內容,它可讓模型更瞭解您所要求的內容,或應該知道的內容以提供最佳答案。 您可以透過數種方式提供內容。

要求輸出組合

指定輸出的結構可能會對結果造成很大的影響。 這可能包括要求模型引用其來源、將回應撰寫為電子郵件、將回應格式化為 SQL 查詢、將情緒分類為特定結構等內容。 例如:

提示

Write a table in markdown with 6 animals in it, with their genus and species

回應

| Animal           | Genus          | Species        |
| ---------------- |:--------------:|:--------------:|
| Red Panda        | Ailurus        | fulgens        |
| African Elephant | Loxodonta      | africana       |
| Snow Leopard     | Panthera       | uncia          |
| Arctic Fox       | Vulpes         | lagopus        |
| Chimpanzee       | Pan            | troglodytes    |
| Siberian Tiger   | Panthera       | tigris altaica |

這項技術可搭配自訂格式使用,例如 JSON 結構:

提示

Put two fictional characters into JSON of the following format

{
  firstNameFictional: 
  jobFictional:
}

回應

Here's an example of how you can put two fictional characters into JSON format:

{
  "firstNameFictional": "Henry",
  "jobFictional": "Wizard"
},
{
  "firstNameFictional": "Frank",
  "jobFictional": "Hero"
}

系統訊息

系統會在提示的開頭包含系統訊息,其設計目的是要提供模型指令、從中回答的觀點,或其他有助於引導模型回應的資訊。 此系統訊息可能包含語氣或個性、不應包含的主題,或回答方式等特定資訊 (如格式)。

例如,您可以為它提供下列系統訊息:

  • 「我希望你像命令列終端一樣運作。 和 cmd.exe 完全一樣地在單一獨特的程式碼區塊中回應命令,而不是其他任何東西。」
  • 「我希望你成為從英文到西班牙文的翻譯工具。 不要回應我說的或詢問的任何內容,只要在這兩種語言之間翻譯,並以翻譯的文字回覆。」
  • 「成為激勵性演講者,自由地提供關於目標和挑戰的建議。 您應該包含許多正面肯定和建議活動,以達到使用者的最終目標。」

其他範例系統訊息可在 Azure OpenAI Studio 的聊天視窗頂端取得。 請嘗試定義自己的系統提示,指定唯一的回應,並與模型聊天,進而查看回應的差異。

端點會 ChatCompletion 啟用使用 System 聊天角色來包含系統訊息。

var chatCompletionsOptions = new ChatCompletionsOptions()
{
    Messages =
    {
        new ChatRequestSystemMessage("You are a casual, helpful assistant. You will talk like an American old western film character."),
        new ChatRequestUserMessage("Can you direct me to the library?")
    }
};

回應

{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "Well howdy there, stranger! The library, huh?
                    Y'all just head down the main road till you hit the town 
                    square. Once you're there, take a left and follow the street 
                    for a spell. You'll see the library on your right, can’t 
                    miss it. Happy trails!",
        "role": "assistant"
      }
    }
  ],
  ...
}
response = openai.ChatCompletion.create(
    model="gpt-35-turbo",
    messages=[
        {"role": "system", "content": "You are a casual, helpful assistant. You will talk like an American old western film character."},
        {"role": "user", "content": "Can you direct me to the library?"}
    ]
)

回應

{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "Well howdy there, stranger! The library, huh?
                    Y'all just head down the main road till you hit the town 
                    square. Once you're there, take a left and follow the street 
                    for a spell. You'll see the library on your right, can’t 
                    miss it. Happy trails!",
        "role": "assistant"
      }
    }
  ],
  ...
}

系統訊息可大幅變更回應 (包括格式和內容)。 請嘗試為模型定義清楚的系統訊息,以確切說明您預期的回應類型,以及您想要包含的回應類型。

交談歷程記錄

除了系統訊息之外,也可以將其他訊息提供給模型,進而增強交談。 交談歷程記錄可讓模型以類似方式 (例如色調或格式設定) 繼續回應,並允許使用者參考後續查詢中的先前內容。 您可以透過兩種方式來提供此歷程記錄:從實際的聊天記錄,或從使用者定義的範例交談提供。

使用 OpenAI 模型的聊天介面,例如 Azure OpenAI Studio 中的 ChatGPT 和聊天遊樂場,會自動包含對話歷程記錄,進而產生更豐富且更有意義的交談。 在 Azure OpenAI Studio 聊天遊樂場聊天視窗下的 [參數] 區段中,您可以指定您想要包含的過去訊息數目。 請嘗試將其減少為 1 或增加至最大值,查看不同數量的歷程記錄如何影響交談。

注意

提示中包含的交談歷程記錄越多,表示會使用較多的輸入權杖。 您必須判斷使用案例的正確餘額,考慮您使用模型的權杖限制。

聊天系統也可利用模型的摘要功能儲存輸入權杖。 應用程式可選擇摘要過去的訊息,並在交談歷程記錄中包含該摘要,且只提供過去幾個訊息給模型。

Few shot learning

使用使用者定義的範例交談就是所謂的「Few shot learning」,它會提供模型範例並說明應如何回應指定的查詢。 這些範例可用來訓練模型的回應方式。

例如,藉由提供模型幾個提示和預期的回應,它會以相同的模式繼續執行,而不會指示它該怎麼做:

User: That was an awesome experience
Assistant: positive
User: I won't do that again
Assistant: negative
User: That was not worth my time
Assistant: negative
User: You can't miss this
Assistant:

如果模型只提供 You can't miss thisfew shot learning 中沒有的額外內容,則回應可能不實用。

實際上,交談歷程記錄和 few shot learning 會以相同的方式傳送至模型;每個使用者訊息和助理回應都是訊息物件中的離散訊息。 ChatCompletion 端點已最佳化並包含訊息歷程記錄,不論此訊息歷程記錄是否作為 few shot learning 或實際交談歷程記錄所提供。

var chatCompletionsOptions = new ChatCompletionsOptions()
{
    Messages =
    {
        new ChatRequestSystemMessage("You are a helpful assistant."),
        new ChatRequestUserMessage("That was an awesome experience"),
        new ChatRequestAssistantMessage("positive"),
        new ChatRequestUserMessage("I won't do that again"),
        new ChatRequestAssistantMessage("negative"),
        new ChatRequestUserMessage("That was not worth my time"),
        new ChatRequestAssistantMessage("negative"),
        new ChatRequestUserMessage("You can't miss this")
    }
};
response = openai.ChatCompletion.create(
    model="gpt-35-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "That was an awesome experience"},
        {"role": "assistant", "content": "positive"},
        {"role": "user", "content": "I won't do that again"},
        {"role": "assistant", "content": "negative"},
        {"role": "user", "content": "That was not worth my time"},
        {"role": "assistant", "content": "negative"},
        {"role": "user", "content": "You can't miss this"}
    ]
)

分解複雜工作

改善互動的另一個技巧是將複雜的提示分割成多個查詢。 這可讓模型進一步瞭解每個個別的部分,並改善整體正確性。 分割提示也可讓您在未來的提示中包含先前提示的回應,並使用該資訊,以及模型的功能來產生有趣的回應。

例如,您可以詢問模型 Doug can ride down the zip line in 30 seconds, and takes 5 minutes to climb back up to the top. How many times can Doug ride the zip line in 17 minutes?。 結果可能是 3,如果 Doug 從滑索頂端開始,則結果不正確。

更有資訊性的答案可能透過詢問它多個問題取得,例如關於回到滑索頂端的來回行程時間,以及如何說明 Doug 從滑索頂端開始的事實。 將此問題分解就能發現 Doug 可以乘坐四次滑索。

思維鏈結

協助您有效地分解工作的其中一個實用方法,就是要求模型解釋其思維鏈結。

要求模型以判斷回應的逐步程式回應,是瞭解模型如何解譯提示的實用方式。 如此一來,您就可以查看模型在何處進行不正確的邏輯回合,並進一步瞭解如何變更提示以避免錯誤。 這項技術可包括要求它引用其來源,就像 Bing 聊天所做的那樣 (使用 GPT-4 產生模型),並提供原因以判斷其答案的理由。

思維提示技術的鏈結最適合用來協助您逐一查看並改善提示,進而從模型取得最高品質的答案。

例如,詢問模型 What sport is easiest to learn but hardest to master? 會產生回應,並回答原因的一小部分說明。 不過,當出現提示 What sport is easiest to learn but hardest to master? Give a step by step approach of your thoughts, ending in your answer 時,回應會完整解釋它如何得出答案。

Sure, here's a step-by-step approach to answering the question:
1. Identify sports that are popular and have a large following.
2. Consider the basic mechanics of each sport and how easy they are to learn.
3. Think about the various techniques and skills required to play each sport at a high level, and how difficult they are to master.
4. Compare the relative ease of learning each sport to the difficulty of mastering it.
5. Based on the above analysis, determine which sport is easiest to learn but hardest to master.

Using this approach, I would say that the sport of golf is easiest to learn but hardest to master. Here's why:
1. Golf is a popular sport with a large following.
2. The basic mechanics of hitting a golf ball are relatively simple and can be learned quickly with some practice.
3. However, achieving consistency and mastering the various shots and techniques required to play at a high level can take years of practice and dedication.
4. Compared to other sports, the difference between a beginner and an intermediate golfer is relatively small, while the difference between an intermediate and an advanced golfer is much larger.
5. Therefore, I would say that golf is the sport that is easiest to learn but hardest to master.

瞭解模型用來形成其回應的原因步驟,可讓我們識別需要分割提示的位置、提供詳細資訊或釐清指示。