所以我试着从对话中创造一个关于维生素的对话。但是,我总是得到同样的错误,正因为如此,人工智能的反应也是一样的。所以我们想要发生的是,(用户)-给我更多关于维生素(AI)的信息-当然。哪种维生素(使用者)-*在这里我们指定哪种维生素,例如-*维生素A ( AI ) -然后AI给出对维生素A的具体反应
请帮帮忙
这是我们实现的代码
const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google')
const VITAMIN_INTENT = 'Vitamin'
const VITAMINS_ENTITY = 'Vitamins'
const app = dialogflow()
app.intent(VITAMIN_INTENT, (conv) => {
const vitamin_type = conv.parameters[VITAMINS_ENTITY].toLowerCase();
if (vitamin_type == 'Vitamin A') {
conv.ask("Sources: carrots, sweet potato, green leafy vegetable, squash")
} else if (vitamin_type == 'Vitamin B') {
conv.ask("Sources: Animal products (such as fish, poultry, meat, eggs, or dairy); Also found in fortified breakfast cereals and enriched soy or rice milk.")
} else if (vitamin_type == 'Vitamin B1') {
conv.ask("Sources: Sunflower seeds, asparagus, lettuce, mushrooms, black beans, navy beans, lentils, spinach, peas, pinto beans, lima beans, eggplant, Brussels sprouts, tomatoes, tuna, whole wheat, soybeans.")
} else if (vitamin_type == 'Vitamin B2') {
conv.ask("Sources:B2 ")
}
})
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)
发布于 2019-01-17 12:24:40
错误500通常表示您的程序由于某种原因而崩溃,尽管如果不查看日志,很难确切说明原因。
我猜在这个角色里
const vitamin_type = conv.parameters[VITAMINS_ENTITY].toLowerCase();你没有一个叫做“维生素”的参数。参数名区分大小写,通常都是小写的。因此,conv.parameters[VITAMINS_ENTITY]计算结果为undefined,而undefined没有函数.toLowerCase()。
此外,您的代码中至少有一个逻辑问题。线
const vitamin_type = conv.parameters[VITAMINS_ENTITY].toLowerCase();这确保字符串vitamin_type在小写中。所以像“维生素a”这样的价值观。
但是,在测试这些值时,需要使用比较,如
if (vitamin_type == 'Vitamin A') {你把它和“维生素A”这样的价值观进行比较。所以这些值永远不会匹配。
由于没有任何一个值匹配,所以您将退出函数而不调用conv.ask(),这将生成一个错误。(虽然不是错误500。)
https://stackoverflow.com/questions/54229378
复制相似问题