There are no code samples for qnamaker SDK at the link provided in the md file:
https://github.com/Azure/azure-sdk-for-python/tree/master/azure-cognitiveservices-knowledge-qnamaker
"For code examples, see QnA Maker on docs.microsoft.com."
Which links to here: https://docs.microsoft.com/en-us/python/api/overview/azure/cognitive-services?view=azure-python
Indeed you can find the qnamaker function definitions, but no code examples to see how they are used. Lack of code samples makes this SDK package and the documentation essentially useless.
In my case, I am trying to batch load Q&A tsv files to a KB and re-train it.
Hi @MadDenker
Yes, the page forgets to point to this:
https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/tree/master/samples/knowledge
Hope this sample could help, I keep this issue open as task for doc update.
Ok this is very helpful. I will try this code today.
I am getting the following error:
create_op = client.knowledgebase.create(create_kb_payload=create_kb_dto)
Traceback (most recent call last):
File "<ipython-input-232-cbda6ca88672>", line 1, in <module>
create_op = client.knowledgebase.create(create_kb_payload=create_kb_dto)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\azure\cognitiveservices\knowledge\qnamaker\operations\knowledgebase_operations.py", line 386, in create
body_content = self._serialize.body(create_kb_payload, 'CreateKbDTO')
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 580, in body
return self._serialize(data, data_type, **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 452, in _serialize
target_obj, data_type, **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 715, in serialize_data
return self._serialize(data, **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 489, in _serialize
new_attr = self.serialize_data(orig_attr, attr_desc['type'], **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 708, in serialize_data
data, data_type[1:-1], **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 783, in serialize_iter
serialized.append(self.serialize_data(d, iter_type, **kwargs))
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 715, in serialize_data
return self._serialize(data, **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 489, in _serialize
new_attr = self.serialize_data(orig_attr, attr_desc['type'], **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 708, in serialize_data
data, data_type[1:-1], **kwargs)
File "C:\Users\lfinco\AppData\Local\Continuum\anaconda3\lib\site-packages\msrest\serialization.py", line 776, in serialize_iter
raise SerializationError("Refuse str type as a valid iter type.")
SerializationError: Refuse str type as a valid iter type.
It does not like the string for the name:
create_kb_dto._attribute_map
Out[235]:
{'name': {'key': 'name', 'type': 'str'},
'qna_list': {'key': 'qnaList', 'type': '[QnADTO]'},
'urls': {'key': 'urls', 'type': '[str]'},
'files': {'key': 'files', 'type': '[FileDTO]'}}
I tried submitting the name as a list with one string in it, but that does not seem to work. Any ideas?
Could you show create_kb_dto construction?
qna = []
for index,row in faqout.iterrows():
qna.append(QnADTO(answer=row.Answer,
questions=row.Question,
metadata=[MetadataDTO(name="Category", value=row.Category),MetadataDTO(name="Group", value=row.Group)])
)
urls = ["https://docs.microsoft.com/en-in/azure/cognitive-services/qnamaker/faqs"]
names = ["FAQ2"]
create_kb_dto = CreateKbDTO(
name=names,
qna_list=qna,
urls=urls
)
The exception states that you passed a string when a list of strings were expected. We got issues with people passing "XYZ" and in place of a list and creating three resources "X", "Y" and "Z" because string are iterables. This could be a critical problem.
Double-checking your code:
This example is correct:
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
)
Ok thanks for this. I will take a closer look.
Ok, I was able to resolve by putting [] aorund my questions. Thank you.