8000 ctor tests · rsliang/botbuilder-python@00d0bd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00d0bd2

Browse files
committed
ctor tests
1 parent 4271921 commit 00d0bd2

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
self._is_legacy_protocol: bool = self._endpoint.host.endswith('v3.0')
4646

4747
self._options: QnAMakerOptions = options or QnAMakerOptions()
48-
self.validate_options(self._options)
48+
self._validate_options(self._options)
4949

5050
self._telemetry_client = telemetry_client or NullTelemetryClient()
5151
self._log_personal_information = log_personal_information or False
@@ -187,16 +187,16 @@ async def get_answers(
187187
"""
188188

189189

190-
hydrated_options = self.hydrate_options(options)
191-
self.validate_options(hydrated_options)
190+
hydrated_options = self._hydrate_options(options)
191+
self._validate_options(hydrated_options)
192192

193-
result = self.query_qna_service(context.activity, hydrated_options)
193+
result = self._query_qna_service(context.activity, hydrated_options)
194194

195-
await self.emit_trace_info(context, result, hydrated_options)
195+
await self._emit_trace_info(context, result, hydrated_options)
196196

197197
return result
198198

199-
def validate_options(self, options: QnAMakerOptions):
199+
def _validate_options(self, options: QnAMakerOptions):
200200
if not options.score_threshold:
201201
options.score_threshold = 0.3
202202

@@ -210,9 +210,9 @@ def validate_options(self, options: QnAMakerOptions):
210210
raise ValueError('QnAMakerOptions.top should be an integer greater than 0')
211211

212212
if not options.strict_filters:
213-
options.strict_filters = [Metadata]
213+
options.strict_filters = []
214214

215-
def hydrate_options(self, query_options: QnAMakerOptions) -> QnAMakerOptions:
215+
def _hydrate_options(self, query_options: QnAMakerOptions) -> QnAMakerOptions:
216216
"""
217217
Combines QnAMakerOptions passed into the QnAMaker constructor with the options passed as arguments into get_answers().
218218
@@ -238,7 +238,7 @@ def hydrate_options(self, query_options: QnAMakerOptions) -> QnAMakerOptions:
238238

239239
return hydrated_options
240240

241-
def query_qna_service(self, message_activity: Activity, options: QnAMakerOptions) -> [QueryResult]:
241+
def _query_qna_service(self, message_activity: Activity, options: QnAMakerOptions) -> [QueryResult]:
242242
url = f'{ self._endpoint.host }/knowledgebases/{ self._endpoint.knowledge_base_id }/generateAnswer'
243243

244244
question = {
@@ -250,15 +250,15 @@ def query_qna_service(self, message_activity: Activity, options: QnAMakerOptions
250250

251251
serialized_content = json.dumps(question)
252252

253-
headers = self.get_headers()
253+
headers = self._get_headers()
254254

255255
response = requests.post(url, data=serialized_content, headers=headers)
256256

257-
result = self.format_qna_result(response, options)
257+
result = self._format_qna_result(response, options)
258258

259259
return result
260260

261-
async def emit_trace_info(self, turn_context: TurnContext, result: [QueryResult], options: QnAMakerOptions):
261+
async def _emit_trace_info(self, turn_context: TurnContext, result: [QueryResult], options: QnAMakerOptions):
262262
trace_info = QnAMakerTraceInfo(
263263
message = turn_context.activity,
264264
query_results = result,
@@ -278,7 +278,7 @@ async def emit_trace_info(self, turn_context: TurnContext, result: [QueryResult]
278278

279279
await turn_context.send_activity(trace_activity)
280280

281-
def format_qna_result(self, qna_result: requests.Response, options: QnAMakerOptions) -> [QueryResult]:
281+
def _format_qna_result(self, qna_result: requests.Response, options: QnAMakerOptions) -> [QueryResult]:
282282
result = qna_result.json()
283283

284284
answers_within_threshold = [
@@ -297,7 +297,7 @@ def format_qna_result(self, qna_result: requests.Response, options: QnAMakerOpti
297297

298298
return answers_as_query_results
299299

300-
def get_headers(self):
300+
def _get_headers(self):
301301
headers = { 'Content-Type': 'application/json' }
302302

303303
if self._is_legacy_protocol:

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
# figure out if 300 milliseconds is ok for python requests library...or 100000
77
class QnAMakerOptions:
8-
def __init__(self, score_threshold: float = 0.0, timeout: int = 0, top: int = 0, strict_filters: [Metadata] = []):
8+
def __init__(
9+
self,
10+
score_threshold: float = 0.0,
11+
timeout: int = 0,
12+
top: int = 0,
13+
strict_filters: [Metadata] = []
14+
):
915
self.score_threshold = score_threshold
1016
self.timeout = timeout
1117
self.top = top

0 commit comments

Comments
 (0)
0