8000 Merge branch 'master' into trboehre/expectReplies · snifhex/botbuilder-python@d416006 · GitHub
[go: up one dir, main page]

Skip to content

Commit d416006

Browse files
authored
Merge branch 'master' into trboehre/expectReplies
2 parents 65149c5 + c15c615 commit d416006

File tree

4 files changed

+173
-3
lines changed

4 files changed

+173
-3
lines changed

libraries/botbuilder-ai/botbuilder/ai/qna/dialogs/qnamaker_dialog.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,12 @@ async def __call_generate_answer(self, step_context: WaterfallStepContext):
292292
# Check if active learning is enabled and send card
293293
# maximum_score_for_low_score_variation is the score above which no need to check for feedback.
294294
if (
295-
is_active_learning_enabled
296-
and response.answers
295+
response.answers
297296
and response.answers[0].score <= self.maximum_score_for_low_score_variation
298297
):
299298
# Get filtered list of the response that support low score variation criteria.
300299
response.answers = qna_client.get_low_score_variation(response.answers)
301-
if len(response.answers) > 1:
300+
if len(response.answers) > 1 and is_active_learning_enabled:
302301
suggested_questions = [qna.questions[0] for qna in response.answers]
303302
message = QnACardBuilder.get_suggestions_card(
304303
suggested_questions,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"activeLearningEnabled": true,
3+
"answers": [
4+
{
5+
"questions": [
6+
"Q1"
7+
],
8+
"answer": "A1",
9+
"score": 80,
10+
"id": 15,
11+
"source": "Editorial",
12+
"metadata": [
13+
{
14+
"name": "topic",
15+
"value": "value"
16+
}
17+
]
18+
},
19+
{
20+
"questions": [
21+
"Q2"
22+
],
23+
"answer": "A2",
24+
"score": 78,
25+
"id": 16,
26+
"source": "Editorial",
27+
"metadata": [
28+
{
29+
"name": "topic",
30+
"value": "value"
31+
}
32+
]
33+
},
34+
{
35+
"questions": [
36+
"Q3"
37+
],
38+
"answer": "A3",
39+
"score": 75,
40+
"id": 17,
41+
"source": "Editorial",
42+
"metadata": [
43+
{
44+
"name": "topic",
45+
"value": "value"
46+
}
47+
]
48+
},
49+
{
50+
"questions": [
51+
"Q4"
52+
],
53+
"answer": "A4",
54+
"score": 50,
55+
"id": 18,
56+
"source": "Editorial",
57+
"metadata": [
58+
{
59+
"name": "topic",
60+
"value": "value"
61+
}
62+
]
63+
}
64+
]
65+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"activeLearningEnabled": false,
3+
"answers": [
4+
{
5+
"questions": [
6+
"Q1"
7+
],
8+
"answer": "A1",
9+
"score": 80,
10+
"id": 15,
11+
"source": "Editorial",
12+
"metadata": [
13+
{
14+
"name": "topic",
15+
"value": "value"
16+
}
17+
]
18+
},
19+
{
20+
"questions": [
21+
"Q2"
22+
],
23+
"answer": "A2",
24+
"score": 78,
25+
"id": 16,
26+
"source": "Editorial",
27+
"metadata": [
28+
{
29+
"name": "topic",
30+
"value": "value"
31+
}
32+
]
33+
},
34+
{
35+
"questions": [
36+
"Q3"
37+
],
38+
"answer": "A3",
39+
"score": 75,
40+
"id": 17,
41+
"source": "Editorial",
42+
"metadata": [
43+
{
44+
"name": "topic",
45+
"value": "value"
46+
}
47+
]
48+
},
49+
{
50+
"questions": [
51+
"Q4"
52+
],
53+
"answer": "A4",
54+
"score": 50,
55+
"id": 18,
56+
"source": "Editorial",
57+
"metadata": [
58+
{
59+
"name": "topic",
60+
"value": "value"
61+
}
62+
]
63+
}
64+
]
65+
}

libraries/botbuilder-ai/tests/qna/test_qna.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT License.
33

44
# pylint: disable=protected-access
5+
# pylint: disable=too-many-lines
56

67
import json
78
from os import path
@@ -811,6 +812,46 @@ async def test_should_answer_with_low_score_without_provided_context(self):
811812
)
812813
self.assertEqual(True, results[0].score < 1, "Score should be low.")
813814

815+
async def test_low_score_variation(self):
816+
qna = QnAMaker(QnaApplicationTest.tests_endpoint)
817+
options = QnAMakerOptions(top=5, context=None)
818+
819+
turn_context = QnaApplicationTest._get_context("Q11", TestAdapter())
820+
response_json = QnaApplicationTest._get_json_for_file(
821+
"QnaMaker_TopNAnswer.json"
822+
)
823+
824+
# active learning enabled
825+
with patch(
826+
"aiohttp.ClientSession.post",
827+
return_value=aiounittest.futurized(response_json),
828+
):
829+
results = await qna.get_answers(turn_context, options)
830+
self.assertIsNotNone(results)
831+
self.assertEqual(4, len(results), "should get four results")
832+
833+
filtered_results = qna.get_low_score_variation(results)
834+
self.assertIsNotNone(filtered_results)
835+
self.assertEqual(3, len(filtered_results), "should get three results")
836+
837+
# active learning disabled
838+
turn_context = QnaApplicationTest._get_context("Q11", TestAdapter())
839+
response_json = QnaApplicationTest._get_json_for_file(
840+
"QnaMaker_TopNAnswer_DisableActiveLearning.json"
841+
)
842+
843+
with patch(
844+
"aiohttp.ClientSession.post",
845+
return_value=aiounittest.futurized(response_json),
846+
):
847+
results = await qna.get_answers(turn_context, options)
848+
self.assertIsNotNone(results)
849+
self.assertEqual(4, len(results), "should get four results")
850+
851+
filtered_results = qna.get_low_score_variation(results)
852+
self.assertIsNotNone(filtered_results)
853+
self.assertEqual(3, len(filtered_results), "should get three results")
854+
814855
@classmethod
815856
async def _get_service_result(
816857
cls,

0 commit comments

Comments
 (0)
0