Classes

Ai
WingbotModel
CachedModel
AiMatching

{AiMatching}

Class responsible for NLP Routing by score

Typedefs

EntityExpression : object
textFilterstring

Text filter function

IntentRule : string | EntityExpression
BotPath : object
IntentAction : object
Entity : object
Intent : object
Result : object
Entity : object
Intent : object
Result : object
Compare : string
Entity : object
Intent : object
EntityExpression : object
IntentRule : string | EntityExpression
RegexpComparator : object
PreprocessorOutput : object
AIRequest : object
 

Ai

Kind: global class

 

ai.confidence : number

Upper threshold - for match method and for navigate method

Kind: instance property of Ai

 

ai.threshold : number

Lower threshold - for disambiguation

Kind: instance property of Ai

 

ai.logger : object

The logger (console by default)

Kind: instance property of Ai

 

ai.matcher : AiMatching

AI Score provider

Kind: instance property of Ai

 

ai.getPrefix(prefix, req)

The prefix translator - for request-specific prefixes

Kind: instance method of Ai
Params

  • prefix string
  • req Request
 

ai.textFilter(text) : textFilter

Preprocess text for NLP For example to remove any confidential data

Kind: instance method of Ai
Params

  • text string
 

ai.mockIntent([intent], [score]) ⇒ this

Usefull method for testing AI routes

Kind: instance method of Ai
Params

  • [intent] string = null - intent name
  • [score] number = - the score of the top intent

Example

const { Tester, ai, Route } = require('bontaut');

const bot = new Route();

bot.use(['intentAction', ai.localMatch('intentName')], (req, res) => {
    res.text('PASSED');
});

describe('bot', function () {
    it('should work', function () {
        ai.mockIntent('intentName');

        const t = new Tester(bot);

        return t.text('Any text')
            .then(() => {
                t.actionPassed('intentAction');

            t.any()
                .contains('PASSED');
        })
    });
});
 

ai.register(model, prefix) ⇒ WingbotModel | T

Registers Wingbot AI model

Kind: instance method of Ai
Params

  • model string | WingbotModel | T - wingbot model name or AI plugin
  • prefix string = "default" - model prefix
 

ai.global(path, intents, [title], [meta]) ⇒ object

Returns matching middleware, that will export the intent to the root router so the intent will be matched in a global context

Kind: instance method of Ai
Returns: object - - the middleware
Params

  • path string
  • intents IntentRule | Array.<IntentRule>
  • [title] string = null - disambiguation title
  • [meta] object - metadata for multibot environments
    • [.targetAppId] object - target application id
    • [.targetAction] object - target action

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.global('route-path', 'intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

ai.local(path, intents, [title]) ⇒ object

Returns matching middleware, that will export the intent to the root router so the intent will be matched in a context of local dialogue

Kind: instance method of Ai
Returns: object - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.global('route-path', 'intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

ai.match(intent) ⇒ function

Returns matching middleware

supports:

  • intents ('intentName')
  • entities ('@entity')
  • entities with conditions ('@entity=PRG,NYC')
  • entities with conditions ('@entity>=100')
  • complex entities ({ entity:'entity', op:'range', compare:[null,1000] })
  • optional entities ({ entity:'entity', optional: true })
  • wildcard keywords ('#keyword#')
  • phrases ('#first-phrase|second-phrase')
  • emojis ('#😄🙃😛')

Kind: instance method of Ai
Returns: function - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.match('intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

ai.shouldDisambiguate(aiActions) ⇒ boolean

Kind: instance method of Ai
Params

 

WingbotModel

Kind: global class

 

new WingbotModel(options, [log])

Params

  • options object
    • [.serviceUrl] string
    • .model string
    • [.cacheSize] number
    • [.matches] number
  • [log] Object
 

wingbotModel._queryModel(text) ⇒ Promise.<Result>

Kind: instance method of WingbotModel
Params

  • text string
 

CachedModel

Kind: global class

 

new CachedModel(options, [log])

Params

  • options object
    • [.cacheSize] number
  • [log] Object
 

cachedModel.resolve(text) ⇒ Promise.<Result>

Kind: instance method of CachedModel
Params

  • text string - the user input
 

cachedModel._queryModel(text) ⇒ Promise.<(Array.<Intent>|Result)>

Kind: instance method of CachedModel
Params

  • text string
 

AiMatching

{AiMatching}

Class responsible for NLP Routing by score

Kind: global class

 

aiMatching.optionalHandicap : number

When the entity is optional, the final score should be little bit lower (0.001 by default)

Kind: instance property of AiMatching

 

aiMatching.redundantEntityHandicap : number

When there are additional entities then required add a handicap for each unmatched entity Also works, when an optional entity was not matched (0.03 by default)

Kind: instance property of AiMatching

 

aiMatching.redundantIntentHandicap : number

When there is additional intent, the final score will be lowered by this value (0.06 by default)

Kind: instance property of AiMatching

 

aiMatching.multiMatchGain : number

When more than one AI features (Intent, Entity, Regex) are matching, enrich the score using the {multiMatchGain} ^ {additionalFeaturesCount} (1.2 by default)

Kind: instance property of AiMatching

 

aiMatching.preprocessRule(intent) ⇒ PreprocessorOutput

Create a rule to be cached inside a routing structure

Kind: instance method of AiMatching
Params

 

aiMatching.match(req, rule) ⇒ Intent | null

Calculate a matching score of preprocessed rule against the request

Kind: instance method of AiMatching
Params

 

aiMatching._matchRegexp(req, regexps) ⇒ boolean

Kind: instance method of AiMatching
Params

 

COMPARE : enum

Kind: global enum
Properties

Name Type Default
EQUAL Compare eq
NOT_EQUAL Compare ne
RANGE Compare range
GT Compare gt
GTE Compare gte
LT Compare lt
LTE Compare lte
 

EntityExpression : object

Kind: global typedef
Properties

Name Type Description
entity string the requested entity
[optional] boolean entity is optional, can be missing in request
[op] Compare comparison operation (eq ne range)
[compare] Array.<string> \ Array.<number> value to compare with
 

textFilter ⇒ string

Text filter function

Kind: global typedef
Returns: string - - filtered text
Params

  • text string - input text
 

IntentRule : string | EntityExpression

Kind: global typedef

 

BotPath : object

Kind: global typedef
Properties

Name Type
path string
 

IntentAction : object

Kind: global typedef
Properties

Name Type
action string
intent Intent
sort number
local boolean
aboveConfidence boolean
[winner] boolean
[title] string
 

Entity : object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : object

Kind: global typedef
Params

 

Result : object

Kind: global typedef
Params

 

Entity : object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : object

Kind: global typedef
Params

 

Result : object

Kind: global typedef
Params

 

Compare : string

Kind: global typedef

 

Entity : object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : object

Kind: global typedef
Params

 

EntityExpression : object

Kind: global typedef
Properties

Name Type Description
entity string the requested entity
[optional] boolean the match is optional
[op] Compare comparison operation
[compare] Array.<string> \ Array.<number> value to compare with
 

IntentRule : string | EntityExpression

Kind: global typedef

 

RegexpComparator : object

Kind: global typedef
Properties

Name Type Description
r RegExp regular expression
t boolean use normalized text
 

PreprocessorOutput : object

Kind: global typedef
Properties

Name Type
regexps Array.<RegexpComparator>
intents Array.<string>
entities Array.<EntityExpression>
 

AIRequest : object

Kind: global typedef
Properties

Name Type
text function
intents Array.<Intent> \ null
entities Array.<Entity>

results matching ""

    No results matching ""