如何在Google Actions NLP (google assistant) Console中取一个随机输入值作为slot变量?

How can I take a random input value as a slot variable in Google Actions NLP (google assistant) Console?

假设我有一个应用程序,我想在其中向某人提供城市的天气。

第一个场景有提示:“你喜欢哪个城市的天气?”

然后我必须收集一个名为 conv.param.city 的 slot/parameter:然后在我的节点 webhook 中使用它:

const { conversation } = require('@assistant/conversation');
const functions = require('firebase-functions');
const app = conversation();

app.handle('schedule', (conv, {location}) => {  
  let temperature = callApi(location);// this part doesn't matter right now

  **conv.add(`You want to know the weather in ${location}`);
  conv.close(`The weather in ${location} is ${temperature}`);
});

exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);

据我所知,您只能接收由 types/intents 预定义的 parameters/slots。我无法列出所有可供训练的城市。我怎么能基本上说:此时用户说什么,就把那个词变成这个变量。

如何使用 Google Actions SDK 执行此操作?

您可以通过将 intent 参数类型设置为自由文本来完成此操作(这里是来自示例存储库之一的 example)。

freeText: {}

如果将此类型应用于意图参数,则可以使用训练短语提供必要的上下文,说明短语中应匹配“单词”的位置(example 来自同一存储库)。

I cannot make a list of all cities that exist to train with.

如果您的 API 可以 return 支持的位置集,则存在另一个选项。您还可以使用 runtime type overrides 从 API 提供的位置列表动态生成类型。这会更准确,但取决于您的数据源。