首页 > 解决方案 > 如何防止 Bixby 中的重复操作执行?

问题描述

我想实现一个胶囊,如果用户提供了计算所需的完整输入,或者如果用户没有在第一个请求中提供完整输入,则要求用户提供必要的输入。如果用户提供完整的请求,一切正常。如果用户没有提供完整的请求,但 Bixby 需要更多信息,我会遇到一些奇怪的行为,其中多次调用计算并且 Bixby 从另一个计算的结果中获取计算的必要信息,看起来像在调试图中。

为了更容易地演示我的问题,我扩展了 dice sample capsule -capsule-sample-dice并将 and 添加numSidesnumDiceRollResultConcept以便我可以访问结果中的 dice 和边数。RollResult.model.bxb 现在看起来像这样:

structure (RollResultConcept) {
  description (The result object produced by the RollDice action.)
  property (sum) {
    type (SumConcept)
    min (Required)
    max (One)
  }
  property (roll) {
    description (The list of results for each dice roll.)
    type (RollConcept)
    min (Required)
    max (Many)
  }
  // The two properties below have been added
  property (numSides) {
    description (The number of sides that the dice of this roll have.)
    type (NumSidesConcept)
    min (Required)
    max (One)
  }
  property (numDice) {
    description (The number of dice in this roll.)
    type (NumDiceConcept)
    min (Required)
    max (One)
  }
}

我还添加了single-lines ,RollResult.view.bxb以便在掷骰后向用户显示边数和骰子数。RollResult.view.bxb:

 result-view {
   match {
     RollResultConcept (rollResult)
   }

   render {
     layout {
       section {
         content {
           single-line {
             text {
               style (Detail_M)
               value ("Sum: #{value(rollResult.sum)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Rolls: #{value(rollResult.roll)}")
             }
           }
           // The two single-line below have been added
           single-line {
             text {
               style (Detail_M)
               value ("Dice: #{value(rollResult.numDice)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Sides: #{value(rollResult.numSides)}")
             }
           }
         }
       }
     }
   }
 }

编辑:我忘了添加我更改的代码RollDice.js,见下文:RollDice.js

// RollDice
// Rolls a dice given a number of sides and a number of dice

// Main entry point
module.exports.function = function rollDice(numDice, numSides) {

  var sum = 0;
  var result = [];

  for (var i = 0; i < numDice; i++) {
    var roll = Math.ceil(Math.random() * numSides);
    result.push(roll);
    sum += roll;
  }

  // RollResult
  return {
    sum: sum,           // required Sum
    roll: result,       // required list Roll
    numSides: numSides, // required for numSides
    numDice: numDice    // required for numDice
  }
}

结束编辑


在模拟器中,我现在运行以下查询

intent {
  goal: RollDice
  value: NumDiceConcept(2)
}

缺少所需的NumSidesConcept.

调试视图显示下图,NumSidesConcept缺少(如预期的那样)。 调试图 1

我现在在模拟器中运行以下查询

intent {
  goal: RollDice
  value: NumDiceConcept(2)
  value: NumSidesConcept(6)
}

这会在调试视图中生成以下图表:

调试图 2

在我看来,为了得到结果,计算被执行了两次。我已经尝试过给feature { transient }模型赋值,但这并没有改变任何东西。谁能告诉我这里发生了什么?我是否不允许在输出中使用相同的原始模型,因为 Bixby 在尝试执行操作时会使用它们?

标签: bixbybixbystudio

解决方案


我尝试像您一样修改代码,但无法运行意图(成功)。

在此处输入图像描述

开始编辑

我添加了额外的行,RollDice.js并且能够看到您所看到的计划。

双重执行的原因是您连续运行意图,Bixby 从第二个意图派生了您未在第一个意图中指定的 NumSidesConcept 的值,并执行了第一个意图。

您可以通过在每个意图中为 NumSidesConcept 和 NumDiceConcept 提供一组不同的值来验证上述内容。

如果你在这两个意图之间给了足够的时间,那么结果会有所不同。在您的场景中,第一个意图正在等待 NumSidesConcept 可用,并且一旦 Planner 找到它(从第二个意图的结果),执行就完成了。

你怎么能避免这种情况?确保每个输入都有一个输入视图,以便 Bixby 可以提示用户输入任何未通过 NL(或 Aligned NL)的值。

结束编辑

这是另一种不需要更改 RollResultConcept 并且将根据您的期望工作的方法(访问 dice 中的骰子数和边数result-view

 result-view {
  match: RollResultConcept (rollResult) {
    from-output: RollDice(action)
  }


   render {
     layout {
       section {
         content {
           single-line {
             text {
               style (Detail_M)
               value ("Sum: #{value(rollResult.sum)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Rolls: #{value(rollResult.roll)}")
             }
           }
           // The two single-line below have been added
           single-line {
             text {
               style (Detail_M)
               value ("Dice: #{value(action.numDice)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Sides: #{value(action.numSides)}")
             }
           }
         }
       }
     }
   }
 }

试一试,让我们知道它是否有效!


推荐阅读