Azure-Samples / cognitive-services-quickstart-code

Code Examples used by the Quickstarts in the Cognitive Services Documentation
MIT License
358 stars 520 forks source link

QnaMaker QuickStart Code: generate_answer: ErrorResponseException: (BadArgument) Invalid input. See details. #268

Open ghost opened 3 years ago

ghost commented 3 years ago

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

after creating knowledgebase in qnamaker, using the sample code under the preview sdk:

def download_kb(client, kb_id):
print("Downloading knowledge base...")
kb_data = client.knowledgebase.download(kb_id=kb_id, environment="Prod")
print("Downloaded knowledge base. It has {} QnAs.".format(len(kb_data.qna_documents)))
download_kb (client=client, kb_id=kb_id)

Downloading knowledge base... Downloaded knowledge base. It has 9 QnAs.

but when i try generate answer, it gives an error message:

def generate_answer(client, kb_id):
    print ("Querying knowledge base...")

    listSearchResults = client.knowledgebase.generate_answer(kb_id, QueryDTO(question = "How do I manage my knowledgebase?"))

    for i in listSearchResults.answers:
        print(f"Answer ID: {i.id}.")
        print(f"Answer: {i.answer}.")
        print(f"Answer score: {i.score}.")

generate_answer(client=client, kb_id=kb_id)

Any log messages given by the failure

ErrorResponseException: (BadArgument) Invalid input. See details.
---------------------------------------------------------------------------
ErrorResponseException                    Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15788/4283219011.py in <module>
      9         print(f"Answer score: {i.score}.")
     10 
---> 11 generate_answer(client=client, kb_id=kb_id)

~\AppData\Local\Temp/ipykernel_15788/4283219011.py in generate_answer(client, kb_id)
      2     print ("Querying knowledge base...")
      3 
----> 4     listSearchResults = client.knowledgebase.generate_answer(kb_id, QueryDTO(question = "How do I manage my knowledgebase?"))
      5 
      6     for i in listSearchResults.answers:

~\AppData\Local\Programs\Python\Python39\lib\site-packages\azure\cognitiveservices\knowledge\qnamaker\operations\knowledgebase_operations.py in generate_answer(self, kb_id, generate_answer_payload, custom_headers, raw, **operation_config)
    520 
    521         if response.status_code not in [200]:
--> 522             raise models.ErrorResponseException(self._deserialize, response)
    523 
    524         deserialized = None

ErrorResponseException: (BadArgument) Invalid input. See details.

Expected/desired behavior

OS and Version?

Windows 11 Version 21H2, Build 22000.120, python 3.9.6

Versions

client.api_version

'v5.0-preview.1'

Mention any other details that might be useful

qnamaker-1 qnamaker-2

fsharpn00b commented 3 years ago

Hello @ali-khawaja,

First, I sincerely apologize for my delayed reply. I just ran the quickstart in question, and am able to reproduce what you are seeing. I am investigating now and will let you know as soon as I find something out.

Thank you, fsharpn00b

fsharpn00b commented 3 years ago

Hello @ali-khawaja,

When I ran:

curl -d '{ "question" : "How do I manage my knowledgebase?" }' -H 'Content-type: application/json' -H 'Ocp-apim-subscription-key: <key>' <endpoint>/qnamaker/v5.0-preview.1/knowledgebases/<KB ID>/generateAnswer

I received the output:

{
  "error": {
    "code": "BadArgument",
    "message": "Invalid input. See details.",
    "details": [
      {
        "code": "ValidationFailure",
        "message": "GenerateAnswer not supported for this kind.",
        "target": "GenerateAnswer"
      }
    ]
  }
}

"GenerateAnswer not supported for this kind" is the error message that results from calling the preview SDK with a QnA Maker endpoint that is not managed.

I thought I was using a managed endpoint, but I was mistaken. Once I switched to a managed endpoint, I was able to query my KB successfully.

I'm not certain you're encountering the same issue, but it seems likely. I would recommend creating a new QnA Maker resource in MS Azure Portal. When you do so, you should see a checkbox to create a managed resource. Be sure to check this checkbox. I would include a screenshot, but unfortunately I don't have access to the Azure Portal at the moment. Nonetheless, please let me know if I can provide more information.

Thank you, fsharpn00b

ghost commented 3 years ago

i did not see any checkbox but i saw this message when i was creating a new qnamaker resource:

image

I also saw this message on this link: https://techcommunity.microsoft.com/t5/azure-ai/introducing-question-answering-in-public-preview/ba-p/2374708

Going forward users will not be able to create a new QnA Maker managed resource. All new resources can be created by enabling Custom question answering feature with Text Analytics.

so i am not sure how you were able to create a managed QnA maker managed resource. i am trying to go through the documentation to configure text analytics, and then select the custom questiojn answering then i'll try the python api again. i'll update this thread once i am done.

image

/ali

fsharpn00b commented 3 years ago

Hi @ali-khawaja,

You are quite correct, and I apologize as I just learned about this change as well. I will be retesting the QnA Maker quickstarts to make sure they work with Text Analytics/custom question answering resources. I will let you know if I run into any issues that might affect you, and I will indeed be interested to hear of your experiences also. Thank you! fsharpn00b

fsharpn00b commented 3 years ago

Hi @ali-khawaja,

I was able to run the QnA Maker managed quickstart (https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/python/QnAMaker/sdk/preview-sdk/quickstart.py) unchanged with a new Text Analytics resource with custom question answering enabled. Please let me know if you run into any issues with it.

Thank you, fsharpn00b