@@ -154,6 +154,7 @@ async def recognize(
154154 turn_context : TurnContext ,
155155 telemetry_properties : Dict [str , str ] = None ,
156156 telemetry_metrics : Dict [str , float ] = None ,
157+ luis_prediction_options : LuisPredictionOptions = None
157158 ) -> RecognizerResult :
158159 """Return results of the analysis (Suggested actions and intents).
159160
@@ -168,7 +169,7 @@ async def recognize(
168169 """
169170
170171 return await self ._recognize_internal (
171- turn_context , telemetry_properties , telemetry_metrics
172+ turn_context , telemetry_properties , telemetry_metrics , luis_prediction_options
172173 )
173174
174175 def on_recognizer_result (
@@ -288,6 +289,7 @@ async def _recognize_internal(
288289 turn_context : TurnContext ,
289290 telemetry_properties : Dict [str , str ],
290291 telemetry_metrics : Dict [str , float ],
292+ luis_prediction_options : LuisPredictionOptions = None
291293 ) -> RecognizerResult :
292294
293295 BotAssert .context_not_none (turn_context )
@@ -299,6 +301,11 @@ async def _recognize_internal(
299301 recognizer_result : RecognizerResult = None
300302 luis_result : LuisResult = None
301303
304+ if luis_prediction_options :
305+ options = self ._merge_options (luis_prediction_options )
306+ else :
307+ options = self ._options
308+
302309 if not utterance or utterance .isspace ():
303310 recognizer_result = RecognizerResult (
304311 text = utterance , intents = {"" : IntentScore (score = 1.0 )}, entities = {}
@@ -307,12 +314,12 @@ async def _recognize_internal(
307314 luis_result = self ._runtime .prediction .resolve (
308315 self ._application .application_id ,
309316 utterance ,
310- timezone_offset = self . _options .timezone_offset ,
311- verbose = self . _options .include_all_intents ,
312- staging = self . _options .staging ,
313- spell_check = self . _options .spell_check ,
314- bing_spell_check_subscription_key = self . _options .bing_spell_check_subscription_key ,
315- log = self . _options . log if self . _options .log is not None else True ,
317+ timezone_offset = options .timezone_offset ,
318+ verbose = options .include_all_intents ,
319+ staging = options .staging ,
320+ spell_check = options .spell_check ,
321+ bing_spell_check_subscription_key = options .bing_spell_check_subscription_key ,
322+ log = options . log if options .log is not None else True ,
316323 )
317324
318325 recognizer_result = RecognizerResult (
@@ -322,8 +329,8 @@ async def _recognize_internal(
322329 entities = LuisUtil .extract_entities_and_metadata (
323330 luis_result .entities ,
324331 luis_result .composite_entities ,
325- self . _options .include_instance_data
326- if self . _options .include_instance_data is not None
332+ options .include_instance_data
333+ if options .include_instance_data is not None
327334 else True ,
328335 ),
329336 )
@@ -336,7 +343,7 @@ async def _recognize_internal(
336343 recognizer_result , turn_context , telemetry_properties , telemetry_metrics
337344 )
338345
339- await self ._emit_trace_info (turn_context , luis_result , recognizer_result )
346+ await self ._emit_trace_info (turn_context , luis_result , recognizer_result , options )
340347
341348 return recognizer_result
342349
@@ -345,11 +352,12 @@ async def _emit_trace_info(
345352 turn_context : TurnContext ,
346353 luis_result : LuisResult ,
347354 recognizer_result : RecognizerResult ,
355+ options : LuisPredictionOptions
348356 ) -> None :
349357 trace_info : Dict [str , object ] = {
350358 "recognizerResult" : LuisUtil .recognizer_result_as_dict (recognizer_result ),
351359 "luisModel" : {"ModelID" : self ._application .application_id },
352- "luisOptions" : {"Staging" : self . _options .staging },
360+ "luisOptions" : {"Staging" : options .staging },
353361 "luisResult" : LuisUtil .luis_result_as_dict (luis_result ),
354362 }
355363
@@ -362,3 +370,11 @@ async def _emit_trace_info(
362370 )
363371
364372 await turn_context .send_activity (trace_activity )
373+
374+ def _merge_options (
375+ self ,
376+ user_defined_options : LuisPredictionOptions
377+ ) -> LuisPredictionOptions :
378+ merged_options = LuisPredictionOptions ()
379+ merged_options .__dict__ .update (user_defined_options .__dict__ )
380+ return merged_options
0 commit comments