Skip to content

Latest commit

 

History

History

kb-node-client

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Provides a NodeJS client wrapper around the Cognitive Services APIs for QnaMaker

Installation

Install on npm

npm install @ads-vdh/qnamaker-api --save

Usage

Initialize the Client:

let qnaMakerApi = require("@ads-vdh/qnamaker-api");

let client = qnaMakerApi({
  endpoint: endpoint,
  apiKey: ocpApimSubscriptionKey,
  kbId: kbId, // optional (sets default for each method)
});

Knowledge Base Methods:

let knowledgeBase = await client.knowledgeBase.download(kbId);
let kbDetails = await client.knowledgeBase.getDetails(kbId);
let knowledgeBases = await client.knowledgeBase.listAll();



await client.knowledgeBase.publish(kbId);
await client.knowledgeBase.replace(kbId, qnaList);

qnaUpdates parameter is a modified qna list:

await client.knowledgeBase.update(kbId, qnaUpdates);

Alterations Methods:

let alterations = await client.alterations.get();
await client.alterations.replace(alterations);

Operations Methods:

await client.operations.getDetails(operationId);
await client.operations.pollForOperationComplete(operationId);

Recommendations

Store your environment variables in a file named .env that looks something like this:

Endpoint=https://***.cognitiveservices.azure.com
kbId=***
OcpApimSubscriptionKey=***

Then use the dot-env package to read them in like this:

require("dotenv").config();

which should then make the environment variables available like this:

let client = qnaMakerApi({
  endpoint: process.env.Endpoint,
  apiKey: process.env.OcpApimSubscriptionKey,
  kbId: process.env.kbId,
});