This is to demo the following
- Programmatically calling QnA Maker and the newer Custom Question Answer service in Azure from an Azure Function
- The business requirement was to have the ability to route different client requests, as part of a quasi-conversational flow, to specific QnA Maker resources globally
- To initiate the service, create a POST request with a JSON body as described in the section titled Incoming request structure below
- The application then looks up the required QnA Maker instance variable required to send the question to the knowledge base
- Lastly, the application returns a string of whatever matched the user question
Note, as seen in the documentation in the References section below, precise answering, a new feature of the new Custom Question Answer service, is only availble from a Bot Service application, not through the API which could be used in something like an Azure Function API call.
While we used phone number as the id for routing a client to a given QnA Maker instance, a more unique organizational level vs client-member, would be a better pattern. It bears mention that in this scenario, each client will need to have a unique QnA Maker instance with a set of Question/Answer pairs that are intended for that organizations members.
The implementation for this is seen in the json file, mentioned below in the Setup section and then from the request perspective in the Incoming request structure below.
- Create a container in Azure blob Storage and save the name to the local.settings.json AZURE_BLOB_CONTAINER_NAME
- Create a routing lookup json file and save the name to the local.settings.json in the CLIENT_LOOKUP_DATA variable
[
{
"id": "phone-number-or-organizational-identifier",
"endpointKeyVar": "your-endPoint-key-from-azure",
"kbId": "your-knowledgebase-id-from-azure-qnamaker",
"endPoint": "your-url-from-qnamaker-in-azure"
}
]
{
"id": "4696001111",
"question": "Luis?"
}