sb-npm-intents
Contains Shared Logic Around the Handling of Intents from the Various NLP Providers
Install
npm install @servisbot/npm-sb-intents
Validation
Supported Validators
Adding a Validator
Validator Usage
To use a validator require it as shown below:
const { validators } = require('@servisbot/npm-sb-intents');
To create an instance of a validator do the following:
const lexValidator = new validators.Lex();
const dialogFlowValidator = new validators.DialogFlow();
Lex Validator
- Alias must start with a letter and contain letters and non-consecutive underscores only.
- Utterance must start with a letter, may only contain letters and white space (with the exception of slots)
- Utterance can contain numbers but the will be converted to their word format. Example "hello 1 2 3" will be converted to "hello one two three"
- Slots must be surrounded by curly braces and can contain alphabetic characters and underscores
Sanitize Alias Sample:
const lexValidator = new validators.Lex();
const invalidAlias = 'i-am-invalid123';
const sanitizedAlias = lexValidator.sanitizeAlias(invalidAlias);
assert(sanitizedAlias, 'i_am_invalid')
Sanitize Utterances Sample:
const lexValidator = new validators.Lex();
const utterances = [
{
text: 'i am valid'
},
{
text: '1 2 3-invalid'
}
];
const sanitizedUtterances = utterances.map((utterance) => lexValidator.sanitizeUtterance(utterance));
Expected:
[
{
text: 'i am valid'
},
{
text: 'one two three invalid'
}
]
Dialog Flow Validator
- Alias may contain any UTF-8 character
- Utterance may contain any UTF-8 character
- Dialog Flow does not currently need to sanitize aliases or utterances
Lift & Shift
The module supports the ability to take nlp specific intent formats and convert them to sb intents.
Watson
To convert a watson skill to sb intents provide stringified JSON to the Watson lift and shift object and call the shift
function e.g.
const { liftShift } = require('@servisbot/npm-sb-intents');
const watsonSkill = {
intents: [
{
intent: 'queue_jump',
examples: [
{
text: 'what is queue jump'
},
{
text: 'what is queuejump'
},
{
text: 'tell me about queue jump'
}
],
description: 'Queue Jump'
},
],
entities: [
{
entity: 'sys-number',
values: []
}
],
dialog_nodes: [
{
type: 'standard',
title: 'queue_jump',
output: {
generic: [
{
values: [
{
text: 'some text'
}
],
response_type: 'text',
selection_policy: 'sequential'
},
]
},
conditions: '#queue_jump',
dialog_node: 'node_43_1584721497513',
previous_sibling: 'node_42_1584721497513'
}
],
counterexamples: [],
learning_opt_out: false,
name: 'AskBotty',
language: 'en',
description: ''
};
const WatsonLiftShift = liftShift.watson;
const botName = 'botty';
const watsonLiftShift = new WatsonLiftShift(watsonSkill, botName);
const sbIntents = watsonLiftShift.shift();
Rasa
All intents must have at least one example in the nlu to be created. Intents that are the first in at least one story will be created as public, otherwise they will be created as private.
To convert a rasa nlu.yml file to sb intents provide the nlu.yml file contents as a string to the Rasa lift and shift object and call the shift
function. e.g.
const { liftShift } = require('@servisbot/npm-sb-intents');
const rasaNluYmlString = `
version: "2.0"
nlu:
- intent: car_rental
examples: |
- I would like to rent a car
- can i rent a car
- how much is it to rent a car
- intent: hotel_booking
examples: |
- can i book a hotel for the night
- where can i book a hotel
- can you suggest a hotel to book
`;
const rasaStoriesYmlString = `
version: "2.0"
stories:
- story: car rental path
steps:
- intent: car_rental
- action: utter_greet
- story: hotel booking path
steps:
- intent: hotel_booking
- action: utter_greet
`;
const RasaLiftShift = liftShift.rasa;
const botName = 'botty';
const rasaLiftShift = new RasaLiftShift({ stories: rasaStoriesYmlString, nlu: rasaNluYmlString}, botName);
const sbIntents = rasaLiftShift.shift();