Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(skills): fixed slot extraction skill
- Loading branch information
1 parent
22f9eb1
commit f5cd610
Showing
5 changed files
with
80 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
modules/basic-skills/src/hooks/after_incoming_middleware/00_extract_slots.js
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
modules/basic-skills/src/hooks/after_incoming_middleware/05_extract_slots.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const _ = require('lodash') | ||
|
||
// Make sure extractedSlots exists | ||
event.state.session.extractedSlots = event.state.session.extractedSlots || {} | ||
rotateTurns() | ||
extractIntentSlots() | ||
extractFromEntityResponse() | ||
|
||
function extractIntentSlots() { | ||
const slots = _.flatten(_.values(event.nlu.slots)).filter(x => !!x.value) // only non-null slots | ||
for (let slot of slots) { | ||
// BETA(11.8.4): Prevent overwrite of the slot if explicitely demanded | ||
if ( | ||
event.state.session.extractedSlots[slot.name] && | ||
event.state.session.extractedSlots[slot.name].overwritable == false | ||
) { | ||
continue | ||
} | ||
|
||
// Slot is an array when the NLU is confused about the results | ||
// The array is sorted by confidence so we take the first index | ||
if (Array.isArray(slot)) { | ||
slot = slot[0] | ||
} | ||
|
||
event.state.session.extractedSlots.notFound = 0 | ||
event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true) | ||
event.state.session.extractedSlots[slot.name] = { | ||
...slot, | ||
timestamp: Date.now(), | ||
turns: 0, | ||
overwritable: true, | ||
expiresAfterTurns: false // BETA(11.8.4): Set this to a number to expire the slot after 'N' turns | ||
} | ||
} | ||
} | ||
|
||
function rotateTurns() { | ||
for (let slot of _.values(event.state.session.extractedSlots)) { | ||
if (typeof slot.turns === 'number') { | ||
++slot.turns | ||
} | ||
|
||
// BETA(11.8.4): Automatically expire the slot after X dialog turns | ||
if (typeof slot.expiresAfterTurns === 'number' && slot.turns >= slot.expiresAfterTurns) { | ||
delete event.state.session.extractedSlots[slot.name] | ||
} | ||
} | ||
} | ||
|
||
function extractFromEntityResponse() { | ||
if (event.state.session.extractedSlots.__currentSlot) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters