@rainbird/sdk

    1.4.4 • Public • Published

    @rainbird/sdk

    pipeline status coverage status

    This package is designed to be a lightweight way to interact with Rainbird. Minimal dependencies to support older (>25% usage, not dead) browsers.

    Installation

    yarn add @rainbird/sdk
    npm i @rainbird/sdk

    Usage

    Common arguments
    Name Type Description Example/Help
    baseURL String The url to be targeted without any params 'https://api.rainbird.ai'
    apiKey String The api key that allows access to the api This can be found in the 'account' section of the Rainbird Studio
    kmID String The ID of the specific knowledge map that you will query This can be found in the map view of the Rainbird Studio
    sessionID String The ID of the current session Returned from the 'start' endpoint
    options Object (optional) Options provided to Rainbird, currently used to interact with different versions of the engine { engine: 'v2.0' }

    Start

    Description: A function to start a session to begin interaction with Rainbird.

    Args: baseURL, apiKey, kmID, options

    Returns: { sessionID, kmVersionID: String }

    Example:

    const sdk = require('@rainbird/sdk');
    
    async function interact(baseURL, apiKey, kmID) {
        try {
            const { sessionID, kmVersionID } = await sdk.start(baseURL, apiKey, kmID, options);
        } catch (e) {
            return e
        }
    }

    Inject

    Description: A function to create facts prior to, or during, a Rainbird query. (Can only be called after starting a session, see start)

    Args: baseURL, sessionID, data (example below), options

    Returns: { ok: Bool }

    Example:

    const sdk = require('@rainbird/sdk');
    
    async function interact(baseURL, sessionID) {
        const data = [
            { subject: "Bob", relationship: "speaks", object: "English", cf: 100 },
            { subject: "Bob", relationship: "lives in", object: "France", cf: 100 }
        ]
    
        try {
            const { ok } = await sdk.inject(baseURL, sessionID, data, options);
        } catch (e) {
            return e
        }
    }

    Query

    Description: A function to ask Rainbird an initial question

    Args: baseURL, sessionID, subject: String, relationship: String, object: String, options

    Returns:

    {
        "question": {
            "allowCF": Bool,
            "allowUnknown": Bool,
            "canAdd": Bool,
            "concepts": [
                {
                    "conceptType": String,
                    "name": String,
                    "type": String,
                    "value": String,
                    "fsid": Num
                }
            ],
            "dataType": String,
            "knownAnswers": Array,
            "object": String,
            "plural": Bool,
            "prompt": String,
            "relationship": String,
            "subject": String,
            "type": String
        },
        "extraQuestions": [{
            "allowCF": Bool,
            "allowUnknown": Bool,
            "canAdd": Bool,
            "concepts": [
                {
                    "conceptType": String,
                    "name": String,
                    "type": String,
                    "value": String,
                    "fsid": Num
                }
            ],
            "dataType": String,
            "knownAnswers": Array,
            "object": String,
            "plural": Bool,
            "prompt": String,
            "relationship": String,
            "subject": String,
            "type": String
        }, ...],
        "sid": String
    }

    Example:

    const sdk = require('@rainbird/sdk');
    
    async function interact(baseURL, apiKey) {
        try {
            const { data } = await sdk.query(baseURL, sessionID, "Person", "Speaks", "");
            return data.question.prompt;
        } catch (e) {
            return e;
        }
    }

    Response

    Description: A function to respond to a question from Rainbird

    Args: baseURL, sessionID, answers: Array[ Object{ subject: String, relationship: String, object: String, cf: Num } ], options

    Returns:

    {
        "data": {
            "question": {
                "allowCF": Bool,
                "allowUnknown": Bool,
                "canAdd": Bool,
                "concepts": [
                    {
                        "conceptType": String,
                        "name": String,
                        "type": String,
                        "value": String,
                        "fsid": Num
                    "}
                ],
                "dataType": String,
                "knownAnswers": Array,
                "object": String,
                "plural": Bool,
                "prompt": String,
                "relationship": String,
                "subject": String,
                "type": String
            },
            "extraQuestions": [{
                "allowCF": Bool,
                "allowUnknown": Bool,
                "canAdd": Bool,
                "concepts": [
                    {
                        "conceptType": String,
                        "name": String,
                        "type": String,
                        "value": String,
                        "fsid": Num
                    }
                ],
                "dataType": String,
                "knownAnswers": Array,
                "object": String,
                "plural": Bool,
                "prompt": String,
                "relationship": String,
                "subject": String,
                "type": String
            }, ...],
            "sid": String
        },
        "type": RESPONSE_TYPE_QUESTION
    }

    OR

    {
        "data": {
            "result": [
                {
                    "certainty": Num,
                    "factID": String,
                    "object": String,
                    "objectMetadata": Object,
                    "relationship": String,
                    "relationshipType": String,
                    "subject": String,
                    "subjectMetadata": Object
                }
            ],
            "sid": String
        },
        "type": RESPONSE_TYPE_RESULT
    }

    OR

    {
        "data": Any,
        "type": RESPONSE_TYPE_UNKNOWN
    }

    Example:

    const sdk = require('@rainbird/sdk');
    
    async function interact(baseURL, apiKey) {
        const answers = [{ subject: "Bob", relationship: "speaks", object: "French", cf: 100 }]
        try {
            const { data, type } = await sdk.response(baseURL, sessionID, answers, {});
        } catch (e) {
            return e;
        }
    }

    Response Types

    Description: Symbols that explain the type of response returned from the response endpoint

    Usage:

    const sdk = require('@rainbird/sdk')
    
    data.type === sdk.RESPONSE_TYPE_QUESTION
    data.type === sdk.RESPONSE_TYPE_RESULT
    data.type === sdk.RESPONSE_TYPE_UNKNOWN

    Undo

    Description: A function to go back a step in the interaction

    Args: baseURL, sessionID, data: Object?, options

    Returns: Response

    Example:

    const sdk = require('@rainbird/sdk');
    
    async function interact(baseURL, apiKey) {
        const answers = [{ subject: "Bob", relationship: "speaks", object: "French", cf: 100 }]
        try {
            const response = await sdk.response(baseURL, sessionID, answers, {});
            const { data, type } = await sdk.undo(baseURL, sessionID);
            // ...
        } catch (e) {
            return e;
        }
    }

    Evidence

    Description: A function that provides the basis for a decision of a fact or rule

    Args: baseURL, sessionID, factID: String (returned from result type response), Options {engine: String, securityKey: String (to access secured evidence, you should pass your evidence key)}

    Returns:

    {
        "fact": {
            "factID": String,
            "certainty": Num,
            "object": {
                "type": String,
                "value": String,
                "dataType": String
            },
            "relationship": {
                "type": String
            },
            "subject": {
                "type": String,
                "value": String,
                "dataType": String
            }
        },
        "rule": {
            "bindings": {
                "S": String,
                "O": String
                ...
            },
            "conditions": [
                {
                    "certainty": Num,
                    "factID": String,
                    "factKey": Num,
                    "object": String,
                    "objectType": String,
                    "relationship": String,
                    "salience": Num,
                    "subject": String
                }
            ]
        },
        "source": String,
        "time": Num
    }

    Example:

    const sdk = require('@rainbird/sdk');
    
    async function getEvidence(baseURL, sessionID, factID) {
        try {
            const response = await sdk.evidence(baseURL, sessionID, factID);
            // ...
        } catch (e) {
            return e;
        }
    }

    Keywords

    none

    Install

    npm i @rainbird/sdk

    DownloadsWeekly Downloads

    121

    Version

    1.4.4

    License

    MIT

    Unpacked Size

    75.4 kB

    Total Files

    29

    Last publish

    Collaborators

    • danrb
    • christneet
    • davidrampling