Azure QnA Maker Client Library for Python

raw JSON →
0.3.1 verified Fri May 01 auth: no python maintenance

Microsoft Azure QnA Maker Client Library for Python enables programmatic management of QnA Maker knowledge bases and endpoints. Current version 0.3.1 is stable but in maintenance mode; Azure recommends migrating to the newer question answering service via azure-ai-language-questionanswering. Release cadence is low.

pip install azure-cognitiveservices-knowledge-qnamaker
error ImportError: cannot import name 'QnAMakerClient' from 'azure.cognitiveservices.knowledge.qnamaker'
cause Often caused by incomplete installation or using a very old version (pre-0.2.0).
fix
Upgrade to the latest: pip install --upgrade azure-cognitiveservices-knowledge-qnamaker
error AttributeError: 'QnAMakerClient' object has no attribute 'knowledgebase'
cause Using the runtime client instead of the management client. The runtime client does not have knowledgebase operations.
fix
Use QnAMakerClient (not QnAMakerRuntimeClient) for knowledge base management.
deprecated QnA Maker service is being retired. Azure recommends using the newer question answering service via the 'azure-ai-language-questionanswering' package.
fix Migrate to azure-ai-language-questionanswering (pip install azure-ai-language-questionanswering)
gotcha The runtime client (QnAMakerRuntimeClient) is imported from a different subpackage ('runtime') than the management client.
fix Use 'from azure.cognitiveservices.knowledge.qnamaker.runtime import QnAMakerRuntimeClient' for runtime operations.
breaking In version 0.3.0, the 'QnAMakerClient' constructor changed: 'endpoint' is now required and the 'base_url' parameter was removed.
fix Pass 'endpoint' as first argument: QnAMakerClient(endpoint, credentials).

Authenticate and list QnA Maker knowledge bases.

import os
from azure.cognitiveservices.knowledge.qnamaker import QnAMakerClient
from azure.cognitiveservices.knowledge.qnamaker.models import QnADTO
from msrest.authentication import CognitiveServicesCredentials

subscription_key = os.environ.get('QNAMAKER_SUBSCRIPTION_KEY', '')
endpoint = os.environ.get('QNAMAKER_ENDPOINT', 'https://<your-resource-name>.cognitiveservices.azure.com')

credentials = CognitiveServicesCredentials(subscription_key)
client = QnAMakerClient(endpoint, credentials)

# List all knowledge bases
kbs = client.knowledgebase.list()
for kb in kbs.knowledgebases:
    print(kb.name, kb.id)