0.1.4 • Published 7 years ago

luis-client v0.1.4

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Luis Client

luis-client is a client sdk to call Microsoft Luis API even you are behind a proxy.

Luis Client is now able to :

  • Predict an utterance and return the intents and attached entities
  • Start a training and Get a Training status
  • create / get / rename / delete an intent
  • create / get / rename/ delete a simple entity
  • create / delete an utterance
  • Get all the utterances

Installation

You need superagent to use the Luis Client You need superagent-proxy to use the Luis Client behind a proxy

npm

npm install luis-client
npm install superagent
npm install superagent-proxy

yarn

yarn add luis-client
yarn add superagent
yarn add superagent-proxy

Getting Started

You have to create a Luis Application following Microsoft Documentation.

Once your application created you will use the Luis Client as http.js

const superagent = require('superagent');
require('superagent-proxy')(superagent)
const agent = superagent.agent();

// set proxy on each request
agent.use((req) => {
    if (process.env.HTTP_PROXY) {
        req.proxy(process.env.HTTP_PROXY);
    }
    return req;
});


module.exports = agent ;

luis.js

const LUISClient = require('luis-client').default;
const agent = require('./http');

const client = new LUISClient({
    appId: '<your application id>',
    appKey: '<your application key>',
    authoringKey: '<your authoring key here>',
    verbose: '<true / false>',
    region: '<your region here>',
    version: '<the luis version>',
    versionId: '<your luis app version>'
}, agent);

Luis Client parameters

  • appId : You will find your application ID in your Luis Application Settings
  • appKey : You will find your application key on the Publish section under Resources and Keys following your region
  • authoringKey : You will find your authoring key in your Luis user settings
  • verbose : Check if you need the verbose return from Luis api
  • region : eastasia, southeastasia, australiaeast, northeurope, westeurope, eastus, eastus2, southcentralus, westcentralus, westus, westus2, brazilsouth. Following Microsoft Luis Refenrence Regions
  • version : Current Luis version 2.0
  • versionId : You will find your published version on the Publish section of your Luis application

Luis existing API calls

Always return a Promise with custom content following the LUIS Cognitive Service API

/********** PREDICT **************/
await client.predict(text);

/********** TRAIN **************/
await client.startTraining();
await client.getTrainingStatus();

/********** INTENTS *************/
await client.createIntent(intentName);
await client.getIntent(intentId);
await client.getIntents();
await client.renameIntent(intentId, intentName);
await client.deleteIntent(intentId);

/********** UTTERANCES/EXAMPLES/LABELS *************/
await client.createUtterance(parameters);
await client.createUtterances(parameters);
await client.deleteUtterance(utteranceId);
await client.getUtterances(skip, take);

/********** ENTITIES *************/
await client.createEntity(entityName);
await client.getEntity(entityId);
await client.getEntities();
await client.renameEntity(entityId, entityName);
await client.deleteEntity(entityId);

Remarks

if you need to add an utterance to your Luis application, you have to be compliant with this json schema.

{
    "type": "object",
    "properties": {
        "text": {
            "type": "string"
        },
        "intentName": {
            "type": "string"
        },
        "entityLabels": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "entityName": {
                        "type": "string"
                    },
                    "startCharIndex": {
                        "type": "integer"
                    },
                    "endCharIndex": {
                        "type": "integer"
                    }
                },
                "required": [
                    "entityName",
                    "startCharIndex",
                    "endCharIndex"
                ]
            }
        }
    }
}

if you need to add several utterances to your Luis application, you have to be compliant with this json schema.

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "text": {
                "type": "string"
            },
            "intentName": {
                "type": "string"
            },
            "entityLabels": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "entityName": {
                            "type": "string"
                        },
                        "startCharIndex": {
                            "type": "integer"
                        },
                        "endCharIndex": {
                            "type": "integer"
                        }
                    },
                    "required": [
                        "entityName",
                        "startCharIndex",
                        "endCharIndex"
                    ]
                }
            }
        },
        "required": [
            "text",
            "intentName",
            "entityLabels"
        ]
    }
}

Sample

If you need more examples, please visits the luis-connect repository

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago