Module azure.qnamaker
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_azure.qnamaker_1.1.0.png)
ballerinax/azure.qnamaker Ballerina library
Overview
This is a generated connector for Azure QnA Maker API v4 OpenAPI specification. The Azure QnA Maker API is a cloud-based Natural Language Processing (NLP) service that allows you to create a natural conversational layer over your data. It is used to find the most appropriate answer for any input from your custom knowledge base (KB) of information. QnA Maker is commonly used to build conversational client applications, which include social media applications, chat bots, and speech-enabled desktop applications.
This module supports Azure QnA Maker API v4.
Prerequisites
Before using this connector in your Ballerina application, complete the following:
-
Create an Azure account
-
Create a resource
-
Obtain tokens by following this guide
Quickstart
To use this connector in your Ballerina application, update the .bal file as follows:
Step 1: Import connector
Import the ballerinax/azure.qnamaker
module into the Ballerina project.
import ballerinax/azure.qnamaker;
Step 2: Create a new connector instance
You can now make the connection configuration using Ocp-Apim-Subscription-Key
.
You can do this step in two ways. You can use any one of this.
-
Option 1 : Configure API Keys in ballerina file directly.
ker:ApiKeysConfig apiKeyConfig = { cpApimSubscriptionKey:"<AZURE_API_KEY>" ubscriptionKey: "<Subscription Key>" ker:Client myClient = check new Client(apiKeyConfig, serviceUrl = "https://<REGION>.api.cognitive.microsoft.com/qnamaker/v4.0");
-
Option 2 : Configure API Keys in
Config.toml
file and configure it in ballerina file, using configurables.- Set up API Keys in
Config.toml
as shown below.
[apiKeyConfig] ocpApimSubscriptionKey = "<AZURE_API_KEY>" subscriptionKey = "<Subscription Key>"
- Configure the client in ballerina file as shown below.
configurable ApiKeysConfig & readonly apiKeyConfig = ?; qnamaker:Client myClient = check new Client(apiKeyConfig, serviceUrl = "https://<REGION>.api.cognitive.microsoft.com/qnamaker/v4.0");
- Set up API Keys in
Step 3: Invoke connector operation
-
Now you can use the operations available within the connector. Note that they are in the form of remote operations.
Following is an example on how to get Knowledgebase Details from API.
Get Knowledgebase Details
public function main() returns error? { qnamaker:KnowledgebaseDTO res = check baseClient->getKnowledgebaseDetail(kID); }
-
Use
bal run
command to compile and run the Ballerina program.