microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.47k stars 2.44k forks source link

Bug in CustomQuestionAnswering.getAnswers method -Botbuilder-ai version 4.15.0 #6556

Closed PuliNath closed 1 year ago

PuliNath commented 1 year ago

Describe the bug the results answers from customQuestionAnswering.getanswers do not contain METADATA, instead the array is empty. whereas direct api call via curl provided from language studio ,does produce the result. To Reproduce Steps to reproduce the behavior:

  1. use the getAnswers method from CustomquestionAnswering class from botbuilder-ai 4.15

Expected behavior The metadata parameter returned from language Studio via CustomQuestionAnswering .getanswers , should have metadata values as trained in the language studio custom question answering.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Could this be due to reason that a dictionary is fetched from the actual/normal curl shared in the language studio portal , the exact same dictionary might have errored out , when converting to an array perhaps? because the result from getanswers method has empty array. adding a link to the library : https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.ai.qna.customquestionanswering.getanswersasync?view=botbuilder-dotnet-stable

PuliNath commented 1 year ago

Adding more context -We are using the botframework SDK , which is on the node.js runtime (https://github.com/microsoft/botframework-sdk) specifically ,https://learn.microsoft.com/en-us/javascript/api/botbuilder-ai/?view=botbuilder-ts-latest package.

const { CustomQuestionAnswering } = require("botbuilder-ai");

const qnaEndpoint = { knowledgeBaseId: projectname endpointKey: key, host: languagestudioHost, qnaServiceType:"Language" }; const qnaMakerOptions = { top: 5 }; const QnAService = new CustomQuestionAnswering(qnaEndpoint, qnaMakerOptions, null,undefined, true)

console.log(await QnAService.getAnswers(context)) //here context is the turncontext.

//the results are accuracte but the results do not contain metaData.

{ "answers": [ { "questions": [ "question 1?", "question 2.0" ], "answer": "rsome answerr...", "confidenceScore": 0.6391, "id": 29, "source": "source.xlsx", "metadata":[] -- ------------->empty??? ( this has key /values trained in portal)

whereas if we make use of old qnamaker class from botbuilder-ai we get the meta data , doing this since qnamaker would be not available from 2025.

PuliNath commented 1 year ago

The issue is on the sdk languageutils.ts file , private formatQnaResult(kbAnswers: KnowledgeBaseAnswers): QnAMakerResults { const qnaResultsAnswers = kbAnswers.answers?.map((kbAnswer: KnowledgeBaseAnswer) => { const qnaResult: QnAMakerResult = { answer: kbAnswer.answer, score: kbAnswer.confidenceScore, metadata: kbAnswer.metadata ? Array.from(kbAnswer.metadata)?.map((nv) => { return { name: nv[0], value: nv[1] }; }) : null,

The highlighted funtion would return [] for objects ,m could u please , let us know if this would be fixed or is fixed in a new version of botbuilder-ai????

anishprasad01 commented 1 year ago

Fixed in JS SDK 4.17.1. Please update your packages.