def create_kb(client): print ("Creating knowledge base...") qna1 = QnADTO( answer="Yes, You can use our [REST APIs](https://docs.microsoft.com/rest/api/cognitiveservices/qnamaker/knowledgebase) to manage your knowledge base.", questions=["How do I manage my knowledgebase?"], metadata=[ MetadataDTO(name="Category", value="api"), MetadataDTO(name="Language", value="REST"), ] ) qna2 = QnADTO( answer="Yes, You can use our [Python SDK](https://pypi.org/project/azure-cognitiveservices-knowledge-qnamaker/) with the [Python Reference Docs](https://docs.microsoft.com/python/api/azure-cognitiveservices-knowledge-qnamaker/azure.cognitiveservices.knowledge.qnamaker?view=azure-python) to manage your knowledge base.", questions=["Can I program with Python?"], metadata=[ MetadataDTO(name="Category", value="api"), MetadataDTO(name="Language", value="Python"), ] ) urls = [] files = [ FileDTO( file_name = "structured.docx", file_uri = "https://github.com/Azure-Samples/cognitive-services-sample-data-files/raw/master/qna-maker/data-source-formats/structured.docx" )] create_kb_dto = CreateKbDTO( name="QnA Maker Python SDK Quickstart", qna_list=[ qna1, qna2 ], urls=urls, files=[], enable_hierarchical_extraction=True, default_answer_used_for_extraction="No answer found.", language="English" ) create_op = client.knowledgebase.create(create_kb_payload=create_kb_dto) create_op_monitor = _monitor_operation(client=client, operation=create_op) # Get knowledge base ID from resourceLocation HTTP header knowledge_base_ID = create_op_monitor.resource_location.replace("/knowledgebases/", "") print("Created KB with ID: {}".format(knowledge_base_ID)) return knowledge_base_ID
def update_kb(client, kb_id): print("Updating knowledge base...") qna3 = QnADTO(answer="goodbye", questions=["bye", "end", "stop", "quit", "done"], metadata=[ MetadataDTO(name="Category", value="Chitchat"), MetadataDTO(name="Chitchat", value="end"), ]) qna4 = QnADTO( answer= "Hello, please select from the list of questions or enter a new question to continue.", questions=["hello", "hi", "start"], metadata=[ MetadataDTO(name="Category", value="Chitchat"), MetadataDTO(name="Chitchat", value="begin"), ], context=QnADTOContext(is_context_only=False, prompts=[ PromptDTO(display_order=1, display_text="Use REST", qna_id=1), PromptDTO( display_order=2, display_text="Use .NET NuGet package", qna_id=2), ])) urls = [ "https://docs.microsoft.com/azure/cognitive-services/QnAMaker/troubleshooting" ] update_kb_operation_dto = UpdateKbOperationDTO(add=UpdateKbOperationDTOAdd( qna_list=[qna3, qna4], urls=urls, files=[]), delete=None, update=None) update_op = client.knowledgebase.update(kb_id=kb_id, update_kb=update_kb_operation_dto) _monitor_operation(client=client, operation=update_op) print("Updated knowledge base.")
def create_kb(client): qna = QnADTO( answer="You can use our REST APIs to manage your knowledge base.", questions=["How do I manage my knowledgebase?"], metadata=[MetadataDTO(name="Category", value="api")]) urls = [ "https://docs.microsoft.com/en-in/azure/cognitive-services/qnamaker/faqs" ] create_kb_dto = CreateKbDTO(name="QnA Maker FAQ from quickstart", qna_list=[qna], urls=urls) create_op = client.knowledgebase.create(create_kb_payload=create_kb_dto) create_op = _monitor_operation(client=client, operation=create_op) return create_op.resource_location.replace("/knowledgebases/", "")