Giter VIP home page Giter VIP logo

cognitive-services-qnamaker-nodejs's Introduction

page_type languages products description urlFragment
sample
javascript
azure
These REST samples show you how to programmatically create,
cognitive-services-qnamaker-nodejs

Cognitive Services QnA Maker Samples in Node.js

These REST samples show you how to programmatically create, update, publish, and replace a QnA Maker knowledge base, amongst many other ways to interact with it. All samples are in Node.js. To view these same samples in other languages:

cognitive-services-qnamaker-csharp

cognitive-services-qnamaker-java

cognitive-services-qnamaker-python

Features

Included are the following samples:

All REST samples revolve around what you can do with a knowledge base, which is made up of FAQs or product manuals where there is a question and an answer. QnA Maker gives you more control over how to answer questions by allowing you to train a chat bot to give answers in a variety of ways that feels more like natural, conversational exchanges.

Getting Started

Prerequisites

For each sample, a subscription key is required from your Azure Portal account.

With the exception of creating a new knowledge base, these samples will require your QnA Maker account knowledge base ID. To find your knowledge base ID, go to My knowledge bases and select View Code on the right. You'll see the http request and your knowledge base ID is in the topmost line: for example, POST /knowledgebases/2700e6b9-91a1-41e9-a958-6d1a98735b10/.... Use only the ID.

Run the sample

  1. Create a Node.js project in your favorite IDE or create one in Visual Studio 2017 by expanding Javascript in the new project popup and selecting Node.js, then Blank Node.js Console Application.

  2. Copy/paste the sample you want to test in the app.js file.

  3. Add your Azure subscription key for QnA Maker and add your knowledge base ID (if applicable) to the code at the top.

  4. Run the sample.

  5. Check your knowledge bases in qnamaker.ai to see changes.

Quickstart

References

cognitive-services-qnamaker-nodejs's People

Contributors

diberry avatar microsoftopensource avatar msftgits avatar v-jaswel avatar v-rajagt-zz avatar wiazur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cognitive-services-qnamaker-nodejs's Issues

[Action Needed] This repo is inactive

This GitHub repository has been identified as a candidate for archival

This repository has had no activity in more than [x amount of time]. Long periods of inactivity present security and code hygiene risks. Archiving will not prevent users from viewing or forking the code. A banner will appear on the repository alerting users that the repository is archived.

Please see https://aka.ms/sunsetting-faq to learn more about this process.

Action

✍️

❗**If this repository is still actively maintained, please simply close this issue. Closing an issue on a repository is considered activity and the repository will not be archived.🔒

If you take no action, this repository is still inactive 30 days from today it will be automatically archived..

Need more help? 🖐️

QnA Maker keeps repeating itself in Slack

Please provide us with the following information:

This issue is for a: (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Running the bot from node.js sending the bot a message in slack or even allow it to sit prompts it to start spewing responses from QnA Maker. It works fine in my Teams channel, but keeps doing this behavior in Slack.

Any log messages given by the failure

none

Expected/desired behavior

Not to repeat itself

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?) Windows 10

Versions

botkit

Mention any other details that might be useful

see attached screenshots


Thanks! We'll be in touch soon.

`require('dotenv').config();

const express = require("express");
const bodyParser = require("body-parser");
// Import Botkit's core features
const { Botkit } = require("botkit");
// Import a platform-specific adapter for slack.
const { SlackAdapter, SlackEventMiddleware, SlackMessageTypeMiddleware } = require('botbuilder-adapter-slack');
const { BotFrameworkAdapter } = require('botbuilder');
const { TwilioAdapter } = require('botbuilder-adapter-twilio-sms');
const { QnAMaker } = require('botbuilder-ai');

// Create an express server with json and urlencoded body parsing
const webserver = express();
webserver.use((req, res, next) => {
req.rawBody = '';
req.on('data', function (chunk) {
req.rawBody += chunk;
});
next();
});
webserver.use(express.json());
webserver.use(express.urlencoded({ extended: true }));

//Create Bot Framework Adapter.
// See https://aka.ms/about-bot-adapter to learn more about adapters and how bots work.
const botAdapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});

// Adaptor for Slack
const slackAdaptor = new SlackAdapter({
// REMOVE THIS OPTION AFTER YOU HAVE CONFIGURED YOUR APP!
//enable_incomplete: true,
// The following options are sufficient for a single team application
// parameters used to secure webhook endpoint
verificationToken: process.env.SLACK_VERIFICATION_TOKEN,
clientSigningSecret: process.env.SLACK_CLIENT_SIGNING_SECRET,
// auth token for a single-team app
botToken: process.env.SLACK_BOT_TOKEN
});

// Use Slack Middleware to emit events that match their original Slack event types.
//slackAdaptor.use(new SlackMessageTypeMiddleware());
//slackAdaptor.use(new SlackEventMiddleware());

// Controller for Slack
const slackController = new Botkit({
webhook_uri: process.env.SLACK_WEBHOOK_URI,
adapter: slackAdaptor,
webserver: webserver
});

// Controller for Teams
const teamsController = new Botkit({
webhook_uri: process.env.TEAMS_WEBHOOK_URI,
adapterConfig: {
appId: process.env.TEAMS_APP_ID,
appPassword: process.env.TEAMS_APP_PASSWORD,
},
webserver: webserver
});

// QnA Integration
const qnaMaker = new QnAMaker({
knowledgeBaseId: process.env.QnAKnowledgebaseId,
endpointKey: process.env.QnAAuthKey,
host: process.env.QnAEndpointHostName
});

// QnA Integration for Teams
teamsController.middleware.ingest.use(async (bot, message, next) => {
if (message.incoming_message.type === 'message') {
const qnaResults = await qnaMaker.getAnswers(message.context);
if (qnaResults[0]) {
// If we got an answer, send it directly
//await message.context.sendActivity(qnaResults[0].answer);
await bot.reply(message, qnaResults[0].answer); // also works
} else {
// If we have no other features, we could just say we didn't find any answers:
//await message.context.sendActivity('No QnA Maker answers were found.');
// Otherwise, just forward to the next BotHandler to see if there are any other matches
next();
}
} else {
next();
}
});

// QnA Integration for Slack
slackController.middleware.ingest.use(async (bot, message, next) => {
if (message.incoming_message.type === 'message') {
const qnaResults = await qnaMaker.getAnswers(message.context);
if (qnaResults[0]) {
// If we got an answer, send it directly
//await message.context.sendActivity(qnaResults[0].answer);
await bot.reply(message, qnaResults[0].answer); // also works
} else {
// If we have no other features, we could just say we didn't find any answers:
await message.context.sendActivity('No QnA Maker answers were found.');
// Otherwise, just forward to the next BotHandler to see if there are any other matches
next();
}
} else {
slackAdaptor.use(new SlackMessageTypeMiddleware());
slackAdaptor.use(new SlackEventMiddleware());
}
});

//Adapter and Controller for Twilio
const smsadapter = new TwilioAdapter({
twilio_number: process.env.TWILIO_NUMBER,
account_sid: process.env.TWILIO_ACCOUNT_SID,
auth_token: process.env.TWILIO_AUTH_TOKEN,
});

const smsController = new Botkit({
adapter: smsadapter,
webserver: webserver
});

// Catch-all for errors.
botAdapter.onTurnError = async (context, error) => {
// This check writes out errors to console log
// NOTE: In production environment, you should consider logging this to Azure
// application insights.
console.error(\n [onTurnError]: ${ error });
// Send a message to the user
await context.sendActivity(Oops. Something went wrong!);
// Clear out state
await conversationState.delete(context);
};

// load developer-created local custom feature modules.
// Load common features for slack and teams
slackController.loadModules(__dirname + '/features/common');
teamsController.loadModules(__dirname + '/features/common');
// Load platform specific features seperately
slackController.loadModules(__dirname + '/features/slack');
teamsController.loadModules(__dirname + '/features/teams');
smsController.loadModules(__dirname + '/features/twilio');

// For running server locally for development purposes
if (require.main === module) {
const http = require("http");
const port = process.env.PORT || 3000;
const httpserver = http.createServer(webserver);
httpserver.listen(port, function () {
console.log("Slack Webhook endpoint online: http://127.0.0.1:" + port + process.env.SLACK_WEBHOOK_URI);
console.log("Teams Webhook endpoint online: http://127.0.0.1:" + port + process.env.TEAMS_WEBHOOK_URI);
});
};`

image

Train Api call to add suggestions to the QnA maker knowledgebase using nodejs doesn't work; gives bad request (400)

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ x ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Call the QnA maker train api function to send feedback to QnA maker, using nodejs.
qnaMaker.callTrainAsync(feedbackRecords)

Any log messages given by the failure

Request failed, returning bad request 400

Expected/desired behavior

Status code: 204 , success

OS and Version?

Windows 10

Versions

nodejs version v10.16.3
"botbuilder": "~4.5.1",
"botbuilder-ai": "~4.5.1",
"botbuilder-azure": "^4.8.0",
"botbuilder-dialogs": "~4.5.1",
"botbuilder-testing": "~4.5.1",

Mention any other details that might be useful


Through Postman the below payload is working fine:
{
"feedbackRecords": [
{
"userId": "sd53lsY=",
"userQuestion": "qna maker with luis",
"qnaId": 4
}
]
}
But in nodejs, the qnaMaker.callTrainAsync(feedbackRecords) function is sending below payload and is throwing bad request 400 error.

{"feedbackRecords":{
"feedbackRecords": [
{
"userId": "sd53lsY=",
"userQuestion": "qna maker with luis",
"qnaId": 4
}
]
}}

Qna maker returns answers with high confidence scores for values like "abcd" which is not in KB, for which azure search also returns null

user query:
{
"question": "abcd",
"top": 20
}

response from qna maker:
{
"questions": [
"How do I add my account?",
],
"answer": "In portal, login and add account",
"score": 81.11
}

for the same query, azure search to which this qna app is linked doesn't return any answer.
If there are no records returned from azure search, how is qna maker portal displaying the answer? Is Qna performing some spell check and mapping "abcd" as "add" in the above query?

QnA Maker gives different scores on each Training

I am using QnA Maker with nodejs.

Steps to reproduce, In the created KB

_Add a file -> Save and Train
Test with random text

remove file -> Save and Train

Again add the same file -> Save and Train
Test same chars _

Is there anything I can do to get same score, or is this expected one ?

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.