Git Product home page Git Product logo

botbuilder-qna-maker's Introduction

Wrapper for Microsoft QnA Maker for Microsoft Bot Framework

###Short sample

const QnA = require('botbuilder-qna-maker');

// Send request to QnA maker, get an answer
const serviceGuid = '<INSERT SERVICE ID>';
const subscriptionKey = '<INSERT SUBSCRIPTION KEY>';

const qna = new QnA(serviceGuid, subscriptionKey);
const answer = await qna.answer('hi!');

console.log(answer);

###What's it for? This package provides a shortcut to call the Microsoft QnA Maker service and get a response. It works with bots written in Node.js using Microsoft Bot Framework (see the botbuilder package), but actually can be used in any code, not just in a bot.

###Methods and Static Members

The constructor takes two required and one optional parameter:

const qna = new QnA(serviceGuid, subscriptionKey, host);

You can get all of them from the Settings page at qnamaker.ai.

As for the host, by default we're using the West US server ( https://westus.api.cognitive.microsoft.com/qnamaker/v2.0) but you can change it if the service becomes available in another region.

Methods:

  • async answer(question) - retrieves an answer and returns it as string, without any metadata.
  • async getRawAnswer(question) - retrieves an answer together with some metadata like the original question and the confidence score. Returns an object.

Static Members: QnA.FAILED_ANSWER = 'No good match found in the KB';

This is the answer returned by QnA maker when there is no suitable answer found. You can use it to output your own message:

if (answer === QnA.FAILED_ANSWER) {
  console.log('Oops, no answer found.');
} else { 
  console.log(answer);
}

###Comments and suggestions If you have any comments, contact me here: https://github.com/catcher-in-the-try/

botbuilder-qna-maker's People

Contributors

anton-bot avatar

Watchers

 avatar  avatar

Forkers

jinweilin

botbuilder-qna-maker's Issues

Short sample error - Unexpected identifier

The short sample fails with the following error on the 8th line:

const answer = await qna.answer('Hi!');
                     ^^^

SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

Apologies if this is a stupid user error on my part.

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.