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 test_dialogflow_response(): from rasa.nlu.emulators.dialogflow import DialogflowEmulator em = DialogflowEmulator() data = { "text": "I want italian food", "intent": { "name": "inform", "confidence": 0.4794813722432127 }, "entities": [{ "entity": "cuisine", "value": "italian", "start": 7, "end": 14 }], } norm = em.normalise_response_json(data) assert norm == { "id": norm["id"], "result": { "action": data["intent"]["name"], "actionIncomplete": False, "contexts": [], "fulfillment": {}, "metadata": { "intentId": norm["result"]["metadata"]["intentId"], "intentName": data["intent"]["name"], "webhookUsed": "false", }, "parameters": { "cuisine": ["italian"] }, "resolvedQuery": data["text"], "score": data["intent"]["confidence"], "source": "agent", }, "sessionId": norm["sessionId"], "status": { "code": 200, "errorType": "success" }, "timestamp": norm["timestamp"], }
def test_dialogflow_response(): from rasa.nlu.emulators.dialogflow import DialogflowEmulator em = DialogflowEmulator() data = { "text": "I want italian food", "intent": {"name": "inform", "confidence": 0.4794813722432127}, "entities": [{"entity": "cuisine", "value": "italian", "start": 7, "end": 14}], } norm = em.normalise_response_json(data) assert norm == { "responseId": norm["responseId"], "queryResult": { "queryText": "I want italian food", "action": "inform", "parameters": {"cuisine": ["italian"]}, "fulfillmentText": "", "fulfillmentMessages": [], "outputContexts": [], "intent": {"name": "inform", "displayName": "inform"}, "intentDetectionConfidence": 0.4794813722432127, }, }
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_dialogflow_request(): from rasa.nlu.emulators.dialogflow import DialogflowEmulator em = DialogflowEmulator() norm = em.normalise_request_json({"text": ["arb text"]}) assert norm == {"text": "arb text", "time": None}