生成器

生成器使用 Google 最新的生成式大语言模型 (LLM) 和您提供的提示,在运行时生成代理行为和响应。可用模型由 Vertex AI 提供。

借助生成器,您可以从 Dialogflow CX 以原生方式调用 LLM,而无需创建自己的外部网络钩子。您可以对生成器进行配置,使其执行您通常要求 LLM 执行的任何操作。

生成器非常适合摘要、参数提取和数据转换等任务,请参阅下面的示例

限制

此功能目前可供使用任何 Dialogflow 语言的代理。请注意,可用模型可能具有更严格的语言限制,请参阅 Vertex AI 了解详情。

了解生成器概念

Vertex AI 文档包含在为 Dialogflow 创建生成器时需要了解的重要信息:

定义生成器

如需创建生成器,请执行以下操作:

  1. 转到 Dialogflow CX 控制台
  2. 选择您的 Google Cloud 项目。
  3. 选择代理。
  4. 点击管理标签页。
  5. 点击 Generators(生成器)。
  6. 点击新建 (Create new)。
  7. 为生成器输入一个描述性的显示名。
  8. 按照概念中的说明输入文本提示、模型和控件。
  9. 点击保存

文本提示在运行时执行期间发送到生成模型。它应该是明确的问题或请求,以便模型生成令人满意的回答。

您可以通过在字词前添加 $ 将字词标记为占位符,使提示与上下文相关。稍后您可以将这些生成器提示占位符与执行方式中的会话参数相关联,并在执行期间将其替换为会话参数值。

定义生成器
定义生成器

有一些特殊的生成器提示占位符不需要与会话参数相关联。这些内置的生成器提示占位符

期限 定义
$conversation 代理与用户之间的对话,不包括用户最后的话语。
$last-user-utterance 上一条用户话语。

在 fulfillment 中使用生成器

您可以在执行方式期间使用生成器(在路由事件处理程序参数等中)。

转到 Fulfillment 窗格的 Generators 部分,并将其展开。 然后,点击添加生成器。现在,您可以选择预定义的生成器,也可以在适当位置定义新的生成器。

选择生成器后,您需要将提示的生成器提示占位符与会话参数相关联。此外,您需要定义包含执行后生成器结果的输出参数。

使用生成器
在 fulfillment 中使用生成器

请注意,您可以在一个执行方式中添加多个并行执行的生成器。

此输出参数可以稍后使用,例如在代理响应中。

使用生成器输出
使用生成器的输出

测试生成器

您可以直接在模拟器中测试 generator 功能。

模拟器中的测试生成器
在模拟器中测试生成器

示例

本部分提供了生成器的示例用例。

内容摘要

此示例展示了如何总结内容。

提示

Your goal is to summarize a given text.

Text:
$text

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

对话摘要

此示例展示了如何提供对话摘要。请注意我们如何在对话历史记录中明确指定开启的对话的前缀,并添加 $last-user-utterance,因为它未包含在 $conversation 中。

提示

Your goal is to summarize a given conversation between a Human and an AI.

Conversation:
${conversation USER:"Human:" AGENT:"AI:"}Human: $last-user-utterance

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

已解决的提示

对于示例对话,发送到生成模型的已解决的提示可以是:

Your goal is to summarize a given conversation between a Human and an AI.

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

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

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 is 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$

## Deserts
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 cannot answer the question given the provided information, you plitely
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:

Codelab

另请参阅生成器 Codelab