如何防止在 Bixby 中重复执行操作?

How to prevent duplicate action execution in Bixby?

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

为了更容易展示我的问题,我扩展了骰子样本胶囊 capsule-sample-dice 并将 numSidesnumDice 添加到 RollResultConcept,这样我就可以访问结果中的骰子数和面数。 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)
  }
}

我还在 RollResult.view.bxb 中添加了 single-lines,以便在掷骰后向用户显示面数和骰子数。 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(如预期)。

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

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

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

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

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

开始编辑

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

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

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

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

如何避免这种情况?确保每个输入都有一个 input-view,以便 Bixby 可以提示用户输入任何未通过 NL(或 Aligned NL)的值。

结束编辑

这是另一种方法,它不需要更改 RollResultConcept 并且会根据您的期望工作(访问 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)}")
             }
           }
         }
       }
     }
   }
 }

试一试,如果有效请告诉我们!