發電機

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

您可以使用生成器,直接從 Dialogflow CX 呼叫 LLM,不必建立自己的外部 Webhook。您可以設定生成器,執行一般要求 LLM 執行的任何動作。

生成器擅長執行摘要、參數擷取、資料轉換等工作,請參閱下方的範例

限制

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

瞭解生成器概念

Vertex AI 說明文件包含重要資訊,有助於您瞭解如何為 Dialogflow CX 建立產生器:

定義產生器

如要建立產生器:

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

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

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

定義產生器
定義產生器

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

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

在執行要求中使用產生器

您可以在履行程序中使用產生器 (在「路徑」、「事件處理常式」、「參數」等位置)。

前往「執行要求」窗格的「產生器」部分,然後展開該部分。 然後按一下「新增產生器」。現在您可以選取預先定義的產生器,或在適當位置定義新的產生器。

選取生成器後,您需要將提示的生成器提示預留位置與工作階段參數建立關聯。如要這麼做,您需要定義輸出參數,其中會包含生成器執行後的結果。在「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. 如果沒有看到「生成式 LLM 輸入內容」欄位,請與支援團隊聯絡