How to use the botbuilder-ai.QnAMaker function in botbuilder-ai

To help you get started, we’ve selected a few botbuilder-ai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botbuilder-js / samples / qna-maker-bot-es6 / app.js View on Github external
// Create server
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
    console.log(`${server.name} listening to ${server.url}`);
});

// Create adapter
const adapter = new BotFrameworkAdapter({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

// Add QnA Maker middleware
// The exported Knowledge Base can be found under `smartLightFAQ.tsv`.
const qnaMaker = new QnAMaker(
    {
        knowledgeBaseId: '',
        endpointKey: '',
        host: ''
    },
    {
        answerBeforeNext: true
    }
);
adapter.use(qnaMaker);

// Listen for incoming requests 
server.post('/api/messages', (req, res) => {
    // Route received request to adapter for processing
    adapter.processActivity(req, res, async (context) => {
        // If `!context.responded`, that means an answer wasn't found for the user's utterance.
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 14.nlp-with-dispatch / bots / dispatchBot.js View on Github external
constructor() {
        super();

        const dispatchRecognizer = new LuisRecognizer({
            applicationId: process.env.LuisAppId,
            endpointKey: process.env.LuisAPIKey,
            endpoint: `https://${ process.env.LuisAPIHostName }.api.cognitive.microsoft.com`
        }, {
            includeAllIntents: true,
            includeInstanceData: true
        }, true);

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

        this.dispatchRecognizer = dispatchRecognizer;
        this.qnaMaker = qnaMaker;

        this.onMessage(async (context, next) => {
            console.log('Processing Message Activity.');

            // First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
            const recognizerResult = await dispatchRecognizer.recognize(context);

            // Top intent tell us which cognitive service to use.
            const intent = LuisRecognizer.topIntent(recognizerResult);
github microsoft / botbuilder-js / samples / qna-translator-es6 / app.js View on Github external
setUserLanguage: setUserLanguage,
    getUserLanguage: getUserLanguage,
    translateBackToUserLanguage: true
});
adapter.use(languageTranslator);

// Add locale converter middleware
const localeConverter = new LocaleConverter({
    toLocale: 'en-us',
    setUserLocale: setUserLocale,
    getUserLocale: getUserLocale,
});
adapter.use(localeConverter);

// Add Qna Maker middleware
const qnaMaker = new QnAMaker({
    knowledgeBaseId: "xxxxxx",
    subscriptionKey: "xxxxxx",
    answerBeforeNext: true,
});
adapter.use(qnaMaker);

// Listen for incoming requests 
server.post('/api/messages', (req, res) => {
    // Route received request to adapter for processing
    adapter.processActivity(req, res, (context) => {
        if (context.activity.type != 'message') {
            return context.sendActivity(`[${context.activity.type} event detected]`);
        }
    });
});
github microsoft / botbuilder-js / samples / qna-translator-ts / lib / app.js View on Github external
translatorKey: "xxxxxx",
    noTranslatePatterns: new Set(),
    nativeLanguages: ['en'],
    setUserLanguage: setUserLanguage,
    getUserLanguage: getUserLanguage
});
adapter.use(languageTranslator);
// Add locale converter middleware
const localeConverter = new botbuilder_ai_1.LocaleConverter({
    toLocale: 'en-us',
    setUserLocale: setUserLocale,
    getUserLocale: getUserLocale
});
adapter.use(localeConverter);
// Add Qna Maker middleware
const qnaMaker = new botbuilder_ai_1.QnAMaker({
    knowledgeBaseId: "xxxxxx",
    subscriptionKey: "xxxxxx"
});
adapter.use(qnaMaker);
// Listen for incoming requests 
server.post('/api/messages', (req, res) => {
    // Route received request to adapter for processing
    adapter.processActivity(req, res, (context) => __awaiter(this, void 0, void 0, function* () {
        if (context.activity.type != 'message') {
            yield context.sendActivity(`[${context.activity.type} event detected]`);
        }
    }));
});
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 70.qnamaker-multiturn-sample / index.js View on Github external
const memoryStorage = new MemoryStorage();

// Create conversation and user state with in-memory storage provider.
const conversationState = new ConversationState(memoryStorage);
const userState = new UserState(memoryStorage);

var endpointHostName = process.env.QnAEndpointHostName;
if (!endpointHostName.startsWith('https://')) {
    endpointHostName = 'https://' + endpointHostName;
}

if (!endpointHostName.includes('/v5.0') && !endpointHostName.endsWith('/qnamaker')) {
    endpointHostName = endpointHostName + '/qnamaker';
}

const qnaService = new QnAMaker({
    knowledgeBaseId: process.env.QnAKnowledgebaseId,
    endpointKey: process.env.QnAEndpointKey,
    host: endpointHostName
});

// Create the main dialog.
const dialog = new RootDialog(qnaService);

// Create the bot's main handler.
const bot = new QnAMultiturnBot(conversationState, userState, dialog);

// Listen for incoming requests.
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (turnContext) => {
        // Route the message to the bot's main handler.
        await bot.run(turnContext);
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 48.qnamaker-active-learning-bot / bots / activelearning-bot.js View on Github external
constructor(conversationState) {
        super();

        this.conversationState = conversationState;

        // Create a property used to store dialog state.
        // See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
        this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);

        // Create a dialog set to include the dialogs used by this bot.
        this.dialogs = new DialogSet(this.dialogState);

        this.qnaMaker = new QnAMaker({
            knowledgeBaseId: process.env.QnAKnowledgebaseId,
            endpointKey: process.env.QnAEndpointKey,
            host: process.env.QnAEndpointHostName
        });

        this.qnaMakerOptions = {
            ScoreThreshold: 0.03,
            Top: 3
        };

        this.dialogHelper = new DialogHelper(this.qnaMaker);

        this.dialogs.add(this.dialogHelper.qnaMakerActiveLearningDialog);
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 51.cafe-bot / dialogs / qna / index.js View on Github external
constructor(botConfig, userProfileAccessor, dialogId) {
            (dialogId === undefined) ? super(QNA_DIALOG) : super(dialogId);

            if (!botConfig) throw new Error('Missing parameter. Bot Configuration is required');
            if (!userProfileAccessor) throw new Error('Missing parameter. User profile property accessor is required');

            this.userProfileAccessor = userProfileAccessor;

            // add recognizer
            const qnaConfig = botConfig.findServiceByNameOrId(QNA_CONFIGURATION);
            if (!qnaConfig || !qnaConfig.kbId) throw new Error(`QnA Maker application information not found in .bot file. Please ensure you have all required QnA Maker applications created and available in the .bot file. See readme.md for additional information\n`);
            this.qnaRecognizer = new QnAMaker({
                knowledgeBaseId: qnaConfig.kbId,
                endpointKey: qnaConfig.endpointKey,
                host: qnaConfig.hostname
            });
        }
        /**
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / samples / sample-assistant / src / services / botServices.ts View on Github external
config.knowledgeBases.forEach((kb: QnaMakerService): void => {
                    const qnaEndpoint: QnAMakerEndpoint = {
                        knowledgeBaseId: kb.kbId,
                        endpointKey: kb.endpointKey,
                        host: kb.hostname
                    };
                    cognitiveModelSet.qnaServices.set(kb.id, new QnAMaker(qnaEndpoint, undefined, telemetryClient, true));
                });
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / samples / sample-skill / src / services / botServices.ts View on Github external
config.knowledgeBases.forEach((kb: QnaMakerService): void => {
                        const qnaEndpoint: QnAMakerEndpoint = {
                            knowledgeBaseId: kb.kbId,
                            endpointKey: kb.endpointKey,
                            host: kb.hostname
                        };
                        const qnaMaker: QnAMaker = new QnAMaker(qnaEndpoint, undefined, telemetryClient, true);

                        if (cognitiveModelSet.qnaServices !== undefined) {
                            cognitiveModelSet.qnaServices.set(kb.id, qnaMaker);
                        }
                    });
                }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 11.qnamaker / bot.js View on Github external
constructor(endpoint, qnaOptions) {
        this.qnaMaker = new QnAMaker(endpoint, qnaOptions);
    }

botbuilder-ai

Cognitive services extensions for Microsoft BotBuilder.

MIT
Latest version published 1 month ago

Package Health Score

84 / 100
Full package analysis