示例#1
0
def test_api_response():
    from rasa_nlu.emulators.api import ApiEmulator
    em = ApiEmulator()
    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": None,
            "actionIncomplete": None,
            "contexts": [],
            "fulfillment": {},
            "metadata": {
                "intentId": norm["result"]["metadata"]["intentId"],
                "intentName": {
                    "confidence": data["intent"]["confidence"],
                    "name": data["intent"]["name"]
                },
                "webhookUsed": "false"
            },
            "parameters": {
                "cuisine": ["italian"]
            },
            "resolvedQuery": data["text"],
            "score": None,
            "source": "agent"
        },
        "sessionId": norm["sessionId"],
        "status": {
            "code": 200,
            "errorType": "success"
        },
        "timestamp": norm["timestamp"]
    }
示例#2
0
def test_api_response():
    from rasa_nlu.emulators.api import ApiEmulator
    em = ApiEmulator()
    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": None,
            "actionIncomplete": None,
            "contexts": [],
            "fulfillment": {},
            "metadata": {
                "intentId": norm["result"]["metadata"]["intentId"],
                "intentName": {
                    "confidence": data["intent"]["confidence"],
                    "name": data["intent"]["name"]
                },
                "webhookUsed": "false"
            },
            "parameters": {
                "cuisine": [
                    "italian"
                ]
            },
            "resolvedQuery": data["text"],
            "score": None,
            "source": "agent"
        },
        "sessionId": norm["sessionId"],
        "status": {
            "code": 200,
            "errorType": "success"
        },
        "timestamp": norm["timestamp"]
    }
示例#3
0
 def __create_emulator(self):
     mode = self.config['emulate']
     if mode is None:
         from rasa_nlu.emulators import NoEmulator
         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() == 'api':
         from rasa_nlu.emulators.api import ApiEmulator
         return ApiEmulator()
     else:
         raise ValueError("unknown mode : {0}".format(mode))
示例#4
0
    def __create_emulator(self):
        """Sets which NLU webservice to emulate among those supported by Rasa"""

        mode = self.config['emulate']
        if mode is None:
            from rasa_nlu.emulators import NoEmulator
            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() == 'api':
            from rasa_nlu.emulators.api import ApiEmulator
            return ApiEmulator()
        else:
            raise ValueError("unknown mode : {0}".format(mode))
示例#5
0
def test_api_request():
    from rasa_nlu.emulators.api import ApiEmulator
    em = ApiEmulator()
    norm = em.normalise_request_json({"q": ["arb text"]})
    assert norm == {"text": "arb text", "model": "default"}
示例#6
0
def test_api_request():
    from rasa_nlu.emulators.api import ApiEmulator
    em = ApiEmulator()
    norm = em.normalise_request_json({"q": ["arb text"]})
    assert norm == {"text": "arb text", "model": "default", "time": None}