10000 [QnA Maker] Multi-turn SDK support for QnAId (#310) · gorpo/botbuilder-python@9d41ec4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d41ec4

Browse files
gurvsingaxelsrz
authored andcommitted
[QnA Maker] Multi-turn SDK support for QnAId (microsoft#310)
* QnAMaker Multi-turn fix * Tests added * Test fix
1 parent 63ebf22 commit 9d41ec4

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

libraries/botbuilder-ai/botbuilder/ai/qna/models/generate_answer_request_body.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class GenerateAnswerRequestBody(Model):
1818
"score_threshold": {"key": "scoreThreshold", "type": "float"},
1919
"strict_filters": {"key": "strictFilters", "type": "[Metadata]"},
2020
"context": {"key": "context", "type": "QnARequestContext"},
21+
"qna_id": {"key": "qnaId", "type": "int"},
2122
}
2223

2324
def __init__(
@@ -27,6 +28,7 @@ def __init__(
2728
score_threshold: float,
2829
strict_filters: List[Metadata],
2930
context: QnARequestContext = None,
31+
qna_id: int = None,
3032
**kwargs
3133
):
3234
"""
@@ -43,6 +45,8 @@ def __init__(
4345
4446
context: The context from which the QnA was extracted.
4547
48+
qna_id: Id of the current question asked.
49+
4650
"""
4751

4852
super().__init__(**kwargs)
@@ -52,3 +56,4 @@ def __init__(
5256
self.score_threshold = score_threshold
5357
self.strict_filters = strict_filters
5458
self.context = context
59+
self.qna_id = qna_id

libraries/botbuilder-ai/botbuilder/ai/qna/models/qnamaker_trace_info.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(
2121
top: int,
2222
strict_filters: List[Metadata],
2323
context: QnARequestContext = None,
24+
qna_id: int = None,
2425
):
2526
"""
2627
Parameters:
@@ -39,6 +40,8 @@ def __init__(
3940
strict_filters: Filters used on query.
4041
4142
context: (Optional) The context from which the QnA was extracted.
43+
44+
qna_id: (Optional) Id of the current question asked.
4245
"""
4346
self.message = message
4447
self.query_results = query_results
@@ -47,3 +50,4 @@ def __init__(
4750
self.top = top
4851
self.strict_filters = strict_filters
4952
self.context = context
53+
self.qna_id = qna_id

libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ def __init__(
1212
top: int = 0,
1313
strict_filters: [Metadata] = None,
1414
context: [QnARequestContext] = None,
15+
qna_id: int = None,
1516
):
1617
self.score_threshold = score_threshold
1718
self.timeout = timeout
1819
self.top = top
1920
self.strict_filters = strict_filters or []
2021
self.context = context
22+
self.qna_id = qna_id

libraries/botbuilder-ai/botbuilder/ai/qna/utils/generate_answer_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def _hydrate_options(self, query_options: QnAMakerOptions) -> QnAMakerOptions:
127127
):
128128
hydrated_options.timeout = query_options.timeout
129129

130-
if query_options.context:
131-
hydrated_options.context = query_options.context
130+
hydrated_options.context = query_options.context
131+
hydrated_options.qna_id = query_options.qna_id
132132

133133
return hydrated_options
134134

@@ -143,6 +143,7 @@ async def _query_qna_service(
143143
score_threshold=options.score_threshold,
144144
strict_filters=options.strict_filters,
145145
context=options.context,
146+
qna_id=options.qna_id,
146147
)
147148

148149
http_request_helper = HttpRequestUtils(self._http_client)
@@ -166,6 +167,7 @@ async def _emit_trace_info(
166167
top=options.top,
167168
strict_filters=options.strict_filters,
168169
context=options.context,
170+
qna_id=options.qna_id,
169171
)
170172

171173
trace_activity = Activity(

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,25 @@ async def test_should_answer_with_high_score_provided_context(self):
710710
context = QnARequestContext(
711711
previous_qna_id=5, prvious_user_query="how do I clean the stove?"
712712
)
713-
options = QnAMakerOptions(top=2, context=context)
713+
options = QnAMakerOptions(top=2, qna_id=55, context=context)
714+
turn_context = QnaApplicationTest._get_context(question, TestAdapter())
715+
response_json = QnaApplicationTest._get_json_for_file(
716+
"AnswerWithHighScoreProvidedContext.json"
717+
)
718+
719+
with patch(
720+
"aiohttp.ClientSession.post",
721+
return_value=aiounittest.futurized(response_json),
722+
):
723+
results = await qna.get_answers(turn_context, options)
724+
self.assertEqual(1, len(results), "Should have received 1 answers.")
725+
self.assertEqual(1, results[0].score, "Score should be high.")
726+
727+
async def test_should_answer_with_high_score_provided_qna_id(self):
728+
qna = QnAMaker(QnaApplicationTest.tests_endpoint)
729+
question: str = "where can I buy?"
730+
731+
options = QnAMakerOptions(top=2, qna_id=55)
714732
turn_context = QnaApplicationTest._get_context(question, TestAdapter())
715733
response_json = QnaApplicationTest._get_json_for_file(
716734
"AnswerWithHighScoreProvidedContext.json"

0 commit comments

Comments
 (0)
0