發電機

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

有了產生器,您就能直接從對話式服務專員 (Dialogflow CX) 呼叫 LLM,而無須自行建立外部 webhook。您可以設定產生器,讓產生器執行平常會要求 LLM 執行的任何操作。

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

限制

這項功能適用於任何 Dialogflow 語言的服務機器人,但可用的模型可能會設有更嚴格的語言限制。詳情請參閱 Vertex AI

瞭解產生器概念

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

定義產生器

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

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

文字提示會在執行階段的執行階段傳送至生成式模型。請提出明確的問題或要求,讓模型產生滿意的回覆。

您可以將字詞標示為預留位置,藉此讓提示具有關聯性,方法是在字詞前方加上 $。您之後可以將這些產生器提示預留位置與執行要求中的工作階段參數建立關聯,並在執行期間將其替換為工作階段參數值。

定義產生器
定義產生器

有特殊的產生器提示預留位置,不需要與工作階段參數建立關聯。這些內建產生器提示預留位置為:

字詞 定義
$conversation 代理程式和使用者之間的對話,不含使用者最後一次發言和代理程式之後的發言。
$last-user-utterance 使用者上次說出的內容。

在執行要求中使用產生器

您可以在執行期間使用產生器 (在路由事件處理常式參數等中)。

前往「Fulfillment」窗格的「Generators」部分,然後展開該部分。然後按一下「新增產生器」。您現在可以選取預先定義的產生器,或在原地定義新的產生器。

選取產生器後,您需要將提示的產生器提示預留位置與工作階段參數建立關聯。為此,您需要定義輸出參數,該參數會在執行後包含產生器的結果。在「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 Conversational Agents (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 工作階段參數使用。

提示:

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:

程式碼實驗室

另請參閱 Generators Codelab

疑難排解

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

  1. 按一下「原始回覆」按鈕:

    原始回應

  2. 找出「Generators LLM Inputs」欄位。將這些欄位視為純文字,檢查 LLM 輸入內容是否合理。如果任何字詞含有 $,請檢查模擬器輸入內容,並確認提示中的 $ 是否為刻意加入 (例如,price is $10 中的 $ 很可能是刻意加入,而 visit $city 則不太可能刻意加入,可能表示誤用或錯誤)。

  3. 如果您沒有看到「生成式 LLM 輸入」欄位,請與支援團隊聯絡