Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GenerateAnswerRequestBody(Model):
"score_threshold": {"key": "scoreThreshold", "type": "float"},
"strict_filters": {"key": "strictFilters", "type": "[Metadata]"},
"context": {"key": "context", "type": "QnARequestContext"},
"qna_id": {"key": "qnaId", "type": "int"},
}

def __init__(
Expand All @@ -27,6 +28,7 @@ def __init__(
score_threshold: float,
strict_filters: List[Metadata],
context: QnARequestContext = None,
qna_id: int = None,
**kwargs
):
"""
Expand All @@ -43,6 +45,8 @@ def __init__(

context: The context from which the QnA was extracted.

qna_id: Id of the current question asked.

"""

super().__init__(**kwargs)
Expand All @@ -52,3 +56,4 @@ def __init__(
self.score_threshold = score_threshold
self.strict_filters = strict_filters
self.context = context
self.qna_id = qna_id
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
top: int,
strict_filters: List[Metadata],
context: QnARequestContext = None,
qna_id: int = None,
):
"""
Parameters:
Expand All @@ -39,6 +40,8 @@ def __init__(
strict_filters: Filters used on query.

context: (Optional) The context from which the QnA was extracted.

qna_id: (Optional) Id of the current question asked.
"""
self.message = message
self.query_results = query_results
Expand All @@ -47,3 +50,4 @@ def __init__(
self.top = top
self.strict_filters = strict_filters
self.context = context
self.qna_id = qna_id
2 changes: 2 additions & 0 deletions libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ def __init__(
top: int = 0,
strict_filters: [Metadata] = None,
context: [QnARequestContext] = None,
qna_id: int = None,
):
self.score_threshold = score_threshold
self.timeout = timeout
self.top = top
self.strict_filters = strict_filters or []
self.context = context
self.qna_id = qna_id
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def _hydrate_options(self, query_options: QnAMakerOptions) -> QnAMakerOptions:
):
hydrated_options.timeout = query_options.timeout

if query_options.context:
hydrated_options.context = query_options.context
hydrated_options.context = query_options.context
hydrated_options.qna_id = query_options.qna_id

return hydrated_options

Expand All @@ -143,6 +143,7 @@ async def _query_qna_service(
score_threshold=options.score_threshold,
strict_filters=options.strict_filters,
context=options.context,
qna_id=options.qna_id,
)

http_request_helper = HttpRequestUtils(self._http_client)
Expand All @@ -166,6 +167,7 @@ async def _emit_trace_info(
top=options.top,
strict_filters=options.strict_filters,
context=options.context,
qna_id=options.qna_id,
)

trace_activity = Activity(
Expand Down
20 changes: 19 additions & 1 deletion libraries/botbuilder-ai/tests/qna/test_qna.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,25 @@ async def test_should_answer_with_high_score_provided_context(self):
context = QnARequestContext(
previous_qna_id=5, prvious_user_query="how do I clean the stove?"
)
options = QnAMakerOptions(top=2, context=context)
options = QnAMakerOptions(top=2, qna_id=55, context=context)
turn_context = QnaApplicationTest._get_context(question, TestAdapter())
response_json = QnaApplicationTest._get_json_for_file(
"AnswerWithHighScoreProvidedContext.json"
)

with patch(
"aiohttp.ClientSession.post",
return_value=aiounittest.futurized(response_json),
):
results = await qna.get_answers(turn_context, options)
self.assertEqual(1, len(results), "Should have received 1 answers.")
self.assertEqual(1, results[0].score, "Score should be high.")

async def test_should_answer_with_high_score_provided_qna_id(self):
qna = QnAMaker(QnaApplicationTest.tests_endpoint)
question: str = "where can I buy?"

options = QnAMakerOptions(top=2, qna_id=55)
turn_context = QnaApplicationTest._get_context(question, TestAdapter())
response_json = QnaApplicationTest._get_json_for_file(
"AnswerWithHighScoreProvidedContext.json"
Expand Down