發電機

生成器會使用 Google 最新的生成式大型語言模型 (LLM) 和您提供的提示詞,在執行階段生成代理行為和回覆。可用模型由 Vertex AI 提供。

生成器可讓您直接從 Dialogflow CX 呼叫 LLM,不必自行建立外部 Webhook。您可以設定生成器,執行通常會要求 LLM 執行的任何工作。

生成器非常適合用於摘要、參數擷取或資料轉換等工作,請參閱下方範例。

限制

這項功能適用於任何 Dialogflow CX 語言的代理,但可用模型可能會有更嚴格的語言限制。詳情請參閱「Vertex AI」。

瞭解生成器概念

Vertex AI 說明文件包含為 Dialogflow CX 建立生成器時,必須瞭解的重要資訊:

定義生成器

如要建立生成器,請按照下列步驟操作:

  1. 前往 Dialogflow CX 控制台。
  2. 選取專案。
  3. 選取代理。
  4. 按一下「管理」分頁標籤。
  5. 按一下「Generators」。
  6. 按一下 [Create new] (建立新意圖)。
  7. 輸入生成器的描述性顯示名稱。
  8. 按照概念一節所述,輸入文字提示、模型和控制項。
  9. 按一下 [儲存]。

在執行階段完成要求時,系統會將文字提示詞傳送至生成模型。請務必清楚提問或提出要求,模型才能生成令人滿意的回覆。

如要讓提示詞內容符合脈絡,可以在字詞前加上 $,將字詞標示為預留位置。稍後,您可以將這些生成器提示詞預留位置與執行要求中的工作階段參數建立關聯,並在執行期間以工作階段參數值取代預留位置。

定義生成器
定義產生器

有些特殊的生成器提示詞預留位置不需要與工作階段參數建立關聯。下表列出內建生成器提示預留位置。

X 項目
$conversation 代理和使用者之間的對話,不包括使用者最後一句話和代理之後的話語。
$last-user-utterance 使用者最後輸入的內容。

在執行要求中使用生成器

您可以在執行要求期間使用生成器 (在「路由」、「事件處理常式」、「參數」等)。

  1. 前往「Fulfillment」窗格的「Generators」部分,然後展開該部分。
  2. 按一下「Add generator」(新增生成器)。
  3. 現在您可以選取預先定義的生成器,或直接定義新的生成器。

選取生成器後,請將提示詞的生成器提示詞預留位置與工作階段參數建立關聯。為此,您需要定義輸出參數,其中會包含執行後生成器的結果。在「Output parameters」(輸出參數) 欄位中,輸入輸出參數的名稱,例如 things-to-do。這項輸出參數會寫入工作階段參數,供日後參考。

接著,您可以使用輸出參數,在稍後參照生成器結果,例如在代理回覆中:I'd recommend doing $session.params.things-to-do。

如要進一步瞭解參數格式和用法,請參閱參數說明文件。

測試生成器

生成器功能可以直接在模擬器中測試。

在模擬器中測試生成器
在模擬工具中測試生成器

範例

本節提供生成器的範例用途。生成器是以大型語言模型 (LLM) 為基礎的生成技術,因此您使用下列範例提示詞時,個別結果可能與本文記錄的輸出內容不同。Google 會盡力傳回所有提示結果。

歸納內容重點

這個範例說明如何生成內容摘要。

提示詞:

Your goal is to summarize a given text.

Text:
$text

A concise summary of the text in 1 or 2 sentences is:

總結對話內容

以下範例說明如何提供對話摘要。

提示詞:

You are an expert at summarizing conversations between a User and an Agent.
When providing the summary, always start with "Dear $email_address, the conversation summary is as follows:"
Provide a summary in a few bullet points.
Try to be as brief as possible with each bullet point,
only noting the key points of the conversation.
Output the summary in markdown format.

Conversation:
$conversation

Summary:

解決問題的提示詞:

以對話範例來說,傳送至生成模型的解析提示詞可能如下:

You are an expert at summarizing conversations between a User and an Agent.
When providing the summary, always start with "Dear joe@example.com conversation summary is as follows:"
Provide a summary in a few bullet points.
Try to be as brief as possible with each bullet point,
only noting the key points of the conversation.
Output the summary in markdown format.

Conversation:
Agent: Good day! What can I do for you today?
User: Hi, which models can I use in Dialogflow CX's generators?
Agent: You can use all models that Vertex AI provides!
User: Thanks, thats amazing!

Summary:

使用 Markdown 設定文字格式

這個範例說明如何使用 Markdown 設定文字格式。

# Instructions

You are presented with a text and your goal is to apply markdown formatting to text.

**NOTE:** Do not change the meaning of the text, only the formatting.

# Example

## Text

Generators allow you to use Googles latest generative models to format text,
or to create a summaries, or even to write code. What an amazing feature.

## Text in Markdown

*Generators* allow you to use Google's latest generative models to

*   format text
*   create a summaries
*   write code

What an amazing feature.

# Your current task

## Text

$text

## Text in Markdown

回答問題

這系列範例說明如何使用生成器回答問題。

首先,您可以依賴生成模型的內部知識來回答問題。請注意,模型會根據訓練資料中的資訊提供答案。我們無法保證答案正確或為最新資訊。

提示詞:運用自身知識回答問題

Your goal is to politely reply to a human with an answer to their question.

The human asked:
$last-user-utterance

You answer:

根據提供的資訊回答問題的提示詞:

如果希望模型根據您提供的資訊回答,可以將資訊加入提示。如果您想提供的資訊不多 (例如小型餐廳菜單或公司聯絡資訊),這個方法就很適合。

# Instructions

Your goal is to politely answer questions about the restaurant menu.
If you cannot answer the question because it's not related to the restaurant
menu or because relevant information is missing from the menu, you politely
decline to answer.

# Restaurant menu:

## Starters
Salat 5$

## Main dishes
Pizza 10$

## Desserts
Ice cream 2$

# Examples

Question: How much is the pizza?
Answer: The pizza is 10$.

Question: I want to order the ice cream.
Answer: We do have ice cream! However, I can only answer questions about the menu.

Question: Do you have spaghetti?
Answer: I'm sorry, we do not have spaghetti on the menu.

# Your current task

Question: $last-user-utterance
Answer:

提示詞:根據動態提供的資訊回答問題

您希望模型根據哪些資訊回答問題,但這些資訊往往太多,無法貼到提示中。在這種情況下,您可以將生成器連結至資料庫或搜尋引擎等資訊檢索系統,根據查詢動態檢索資訊。您可以將該系統的輸出內容儲存為參數,並連結至提示中的預留位置。

# Instructions

Your goal is to politely answer questions based on the provided information.
If you can't answer the question given the provided information, you politely
decline to answer.

# Provided information:
$information

Question: $last-user-utterance
Answer:

正在生成程式碼

這個範例說明如何使用生成器編寫程式碼!請注意,這裡適合使用專門訓練來生成程式碼的生成式模型。

提示詞:

# Instructions:

Your goal is to write code in a given programming language solving a given problem.

Problem to solve:
$problem

Programming language:
$programming-language

# Solution:

轉接給真人服務專員

這個範例說明如何處理轉接給真人服務專員的情況。提示中的最後兩項指令可防止模型過於冗長。

提示詞:

# Instructions:

You are a polite customer service agent that handles requests
from users to speak with an operator.

Based on the $last-user-utterance,
respond to the user appropriately about their request to speak with an operator.
Always be polite and assure the user that you
will do your best to help their situation.

Do not ask the user any questions.
Do not ask the user if there is anything you can do to help them.

# Answer:

生成搜尋查詢

這個範例說明如何最佳化使用者提供的 Google 搜尋查詢。

提示詞:

# Instructions:

You are an expert at Google Search and using "Google Fu"
to build concise search terms that provide the highest quality results.
A user will provide an example query,
and you will attempt to optimize this to be the best Google Search query possible.

# Example:

User: when was covid-19 first started and where did it originated from?
Agent: covid-19 start origin

# Your task:

User: $text
Agent:

擷取顧客個人資訊

這個範例說明如何執行資訊檢索,以及搜尋以字串或 JSON 格式提供的資料。Dialogflow CX 工作階段參數通常會使用這些格式。

提示詞:

You are a database engineer and specialize in extracting information
from both structured and unstructured data formats like CSV, SQL, JSON,
and also plain text.

Given a $user_db, extract the information requested
by the user from the $last-user-utterance

EXAMPLE:
user_db: {'customer_name': 'Patrick', 'balance': '100'}
User: What is my current account balance?
Agent: Your current balance is 100.

Begin!

user_db: $user_db
User: $last-user-utterance
Agent:

更新 JSON 物件

這個範例說明如何接受使用者 (或 Webhook) 輸入的 JSON 物件,然後根據使用者的要求操控該物件。

提示詞:

You are an expert Software Engineer
that specializes in the JSON object data structure.

Given some user $update_request and existing $json_object,
you will modify the $json_object based on the user's $update_request.

EXAMPLE:
json_object = { "a": 1, "b": 123 }
User: Add a new key/value pair to my JSON
Agent: What do you want to add?
User: c: cat
Agent: { "a": 1, "b": 123, "c": "cat"}

json_object = {"accounts": [{"username": "user1", "account_number": 12345}, {"username": "user2", "account_number": 98765}], "timestamp": "2023-05-25", "version":"1.0"}
User: Add a new value for user1
Agent: What do you want to add?
User: birthday, 12/05/1982
Agent: {"accounts": [{"username": "user1", "account_number": 12345, "birthday": "12/05/1982"}, {"username": "user2", "account_number": 98765}], "timestamp": "2023-05-25", "version":"1.0"}

json_object = $json_object
User: Add a new key value to my db
Agent: What do you want to add?
User: $last-user-utterance
Agent:

程式碼實驗室

另請參閱生成器程式碼實驗室。

疑難排解

如要對這項功能進行偵錯,可以在 Dialogflow 控制台模擬器中,檢查已解析的大型語言模型 (LLM) 輸入提示:

  1. 點選「原始回覆」按鈕:

    原始回覆

  2. 找到「Generators LLM Inputs」欄位。請以純文字形式讀取這些欄位,並檢查 LLM 輸入內容是否合理。如果任何詞組包含 $,請檢查模擬器輸入內容,並釐清提示中的 $ 是否為刻意 (例如,price is $10 中的 $ 可能是刻意,而 visit $city 則可能不是,且可能暗示誤用或錯誤)。

  3. 如果找不到「Generative LLM Inputs」欄位,請聯絡支援團隊。