def test_intent_from_parse__single_parameter_single_slot(): parse_result = { 'input': 'I want a dark roast espresso', 'intent': { 'intentName': 'AskEspresso', 'probability': 0.56 }, 'slots': [{ 'range': { 'start': 9, 'end': 13 }, 'rawValue': 'dark', 'value': { 'kind': 'Custom', 'value': 'dark' }, 'entity': 'CoffeeRoast', 'slotName': 'roast' }] } prediction_component = _get_prediction_component() result = prediction_component.intent_from_parse_result( pf.from_dict(parse_result)) assert result == ca.AskEspresso(roast="dark")
def test_prediction_from_parse_renders_language(): prediction_component = _get_prediction_component() prediction_component.intent_from_parse_result = MagicMock( return_value=ca.AskEspresso(roast="dark")) parse_result = pf.from_dict({ 'input': 'fake message', 'intent': { 'intentName': 'fake intent', 'probability': 0.677 }, 'slots': [] }) result = prediction_component.prediction_from_parse_result( parse_result, LanguageCode.ENGLISH) assert result.fulfillment_text in [ "dark roast espresso, good choice!", "Alright, dark roasted espresso for you" ] messages = result.fulfillment_messages.for_group( IntentResponseGroup.DEFAULT) assert messages assert messages[0].choices == [ "dark roast espresso, good choice!", "Alright, dark roasted espresso for you" ] with pytest.warns(DeprecationWarning): messages = result.fulfillment_messages(IntentResponseGroup.DEFAULT) assert messages assert messages[0].choices == [ "dark roast espresso, good choice!", "Alright, dark roasted espresso for you" ]
def test_predict_default_language(): class MockSnipsEngine: def parse(self, message): return { 'input': 'I want an espresso', 'intent': { 'intentName': 'AskEspresso', 'probability': 0.677 }, 'slots': [] } c = SnipsConnector(ca.CoffeeAgent) c.nlu_engines = { LanguageCode.ENGLISH: MockSnipsEngine(), LanguageCode.ITALIAN: MockSnipsEngine() } result = c.predict("Fake text, response is mocked anyway...") expected_messages = { IntentResponseGroup.DEFAULT: [ TextIntentResponse(choices=[ "medium roast espresso, good choice!", "Alright, medium roasted espresso for you" ]) ] } assert result.intent == ca.AskEspresso() assert result.confidence == 0.677 assert result.fulfillment_messages == expected_messages with pytest.warns(DeprecationWarning): assert result.fulfillment_message_dict == expected_messages
def test_intent_from_parse__default_parameter(): parse_result = { 'input': 'I want an espresso', 'intent': { 'intentName': 'AskEspresso', 'probability': 0.677 }, 'slots': [] } prediction_component = _get_prediction_component() result = prediction_component.intent_from_parse_result( pf.from_dict(parse_result)) assert result == ca.AskEspresso()