def test_luis_response_without_role(): em = LUISEmulator() data = { "text": "I want italian food", "intent": {"name": "restaurant_search", "confidence": 0.737014589341683}, "intent_ranking": [ {"confidence": 0.737014589341683, "name": "restaurant_search"} ], "entities": [{"entity": "cuisine", "value": "italian"}], } norm = em.normalise_response_json(data) assert norm == { "query": data["text"], "prediction": { "normalizedQuery": data["text"], "topIntent": "restaurant_search", "intents": {"restaurant_search": {"score": 0.737014589341683}}, "entities": { "cuisine": ["italian"], "$instance": { "cuisine": [ { "role": None, "type": "cuisine", "text": "italian", "startIndex": None, "length": None, "score": None, "modelType": None, } ] }, }, }, }
def test_emulators_can_handle_missing_data(): from rasa.nlu.emulators.luis import LUISEmulator em = LUISEmulator() norm = em.normalise_response_json({ "text": "this data doesn't contain an intent result"}) assert norm["topScoringIntent"] is None assert norm["intents"] == []
def test_luis_response(): em = LUISEmulator() data = { "text": "I want italian food", "intent": {"name": "restaurant_search", "confidence": 0.737014589341683}, "intent_ranking": [ {"confidence": 0.737014589341683, "name": "restaurant_search"}, {"confidence": 0.11605464483122209, "name": "goodbye"}, {"confidence": 0.08816417744097163, "name": "greet"}, {"confidence": 0.058766588386123204, "name": "affirm"}, ], "entities": [ { "entity": "cuisine", "value": "italian", "role": "roleCuisine", "extractor": "SpacyEntityExtractor", "start": 7, "end": 14, } ], } norm = em.normalise_response_json(data) assert norm == { "query": data["text"], "prediction": { "normalizedQuery": data["text"], "topIntent": "restaurant_search", "intents": { "restaurant_search": {"score": 0.737014589341683}, "goodbye": {"score": 0.11605464483122209}, "greet": {"score": 0.08816417744097163}, "affirm": {"score": 0.058766588386123204}, }, "entities": { "roleCuisine": ["italian"], "$instance": { "roleCuisine": [ { "role": "roleCuisine", "type": "cuisine", "text": "italian", "startIndex": 7, "length": len("italian"), "score": None, "modelType": "SpacyEntityExtractor", } ] }, }, }, }
def _create_emulator(mode: Optional[Text]) -> NoEmulator: """Create emulator for specified mode. If no emulator is specified, we will use the Rasa NLU format.""" if mode is None: return NoEmulator() elif mode.lower() == "wit": from rasa.nlu.emulators.wit import WitEmulator return WitEmulator() elif mode.lower() == "luis": from rasa.nlu.emulators.luis import LUISEmulator return LUISEmulator() elif mode.lower() == "dialogflow": from rasa.nlu.emulators.dialogflow import DialogflowEmulator return DialogflowEmulator() else: raise ErrorResponse( 400, "BadRequest", "Invalid parameter value for 'emulation_mode'. " "Should be one of 'WIT', 'LUIS', 'DIALOGFLOW'.", { "parameter": "emulation_mode", "in": "query" }, )
def _create_emulator(mode: Optional[Text]) -> NoEmulator: """Create emulator for specified mode. If no emulator is specified, we will use the Rasa NLU format.""" if mode is None: return NoEmulator() elif mode.lower() == 'wit': from rasa.nlu.emulators.wit import WitEmulator return WitEmulator() elif mode.lower() == 'luis': from rasa.nlu.emulators.luis import LUISEmulator return LUISEmulator() elif mode.lower() == 'dialogflow': from rasa.nlu.emulators.dialogflow import DialogflowEmulator return DialogflowEmulator() elif mode.lower() == 'lite': from litemind.nlu.emulators.lite import LiteEmulator return LiteEmulator() elif mode.lower() == 'coref': from litemind.nlu.emulators.coref import CorefEmulator return CorefEmulator() elif mode.lower() == 'entity': from litemind.nlu.emulators.entity import EntityEmulator return EntityEmulator() elif mode.lower() == 'link': from litemind.nlu.emulators.link import LinkEmulator return LinkEmulator() elif mode.lower() == 'relation': from litemind.nlu.emulators.relation import RelationEmulator return RelationEmulator() else: raise ValueError("unknown emulator mode : {0}".format(mode))
def _create_emulator(mode: Optional[Text]) -> NoEmulator: """Create emulator for specified mode. If no emulator is specified, we will use the Rasa NLU format.""" if mode is None: return NoEmulator() elif mode.lower() == 'wit': from rasa.nlu.emulators.wit import WitEmulator return WitEmulator() elif mode.lower() == 'luis': from rasa.nlu.emulators.luis import LUISEmulator return LUISEmulator() elif mode.lower() == 'dialogflow': from rasa.nlu.emulators.dialogflow import DialogflowEmulator return DialogflowEmulator() else: raise ValueError("unknown mode : {0}".format(mode))
def test_luis_response(): from rasa.nlu.emulators.luis import LUISEmulator em = LUISEmulator() data = { "text": "I want italian food", "intent": { "name": "restaurant_search", "confidence": 0.737014589341683 }, "intent_ranking": [ { "confidence": 0.737014589341683, "name": "restaurant_search" }, { "confidence": 0.11605464483122209, "name": "goodbye" }, { "confidence": 0.08816417744097163, "name": "greet" }, { "confidence": 0.058766588386123204, "name": "affirm" }, ], "entities": [{ "entity": "cuisine", "value": "italian" }], } norm = em.normalise_response_json(data) assert norm == { "query": data["text"], "topScoringIntent": { "intent": "restaurant_search", "score": 0.737014589341683 }, "intents": [ { "intent": "restaurant_search", "score": 0.737014589341683 }, { "intent": "goodbye", "score": 0.11605464483122209 }, { "intent": "greet", "score": 0.08816417744097163 }, { "intent": "affirm", "score": 0.058766588386123204 }, ], "entities": [{ "entity": e["value"], "type": e["entity"], "startIndex": None, "endIndex": None, "score": None, } for e in data["entities"]], }
def test_luis_request(): from rasa.nlu.emulators.luis import LUISEmulator em = LUISEmulator() norm = em.normalise_request_json({"text": ["arb text"]}) assert norm == {"text": "arb text", "time": None}
def test_luis_request(): em = LUISEmulator() norm = em.normalise_request_json({"text": ["arb text"]}) assert norm == {"text": "arb text", "time": None}