Exemplo n.º 1
0
 def test_get_utterance_from_empty_intent(self):
     processor = MongoProcessor()
     with pytest.raises(AssertionError):
         response = processor.get_utterance_from_intent("", "tests")
Exemplo n.º 2
0
 def test_add_none_response_name(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_text_response("Greet", None, "tests", "testUser")
Exemplo n.º 3
0
 def test_add_empty_story_event(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_story("happy path", [], "tests", "testUser")
Exemplo n.º 4
0
 def test_add_action_duplicate(self):
     processor = MongoProcessor()
     with pytest.raises(Exception):
         assert processor.add_action("utter_priority", "tests",
                                     "testUser") == None
Exemplo n.º 5
0
 def test_add_text_response_duplicate(self):
     processor = MongoProcessor()
     with pytest.raises(Exception):
         processor.add_text_response("Great", "utter_happy", "tests",
                                     "testUser")
Exemplo n.º 6
0
 def test_get_entities(self):
     processor = MongoProcessor()
     expected = ["priority", "file_text", "ticketID"]
     actual = processor.get_entities("tests")
     assert actual.__len__() == expected.__len__()
     assert all(item["name"] in expected for item in actual)
Exemplo n.º 7
0
 def test_add_empty_entity(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_entity("", "tests", "testUser")
Exemplo n.º 8
0
 def test_add_training_example_blank_text(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_training_example("  ", "greeting", "tests",
                                        "testUser")
Exemplo n.º 9
0
 def test_add_training_example_blank_intent(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_training_example("Hi! How are you", "  ", "tests",
                                        "testUser")
Exemplo n.º 10
0
 def test_download_data_files(self):
     processor = MongoProcessor()
     file = processor.download_files("tests")
     assert file.endswith(".zip")
Exemplo n.º 11
0
 def test_add_same_training_example(self):
     processor = MongoProcessor()
     with pytest.raises(Exception):
         processor.add_training_example("Hi", "greeting", "tests",
                                        "testUser")
Exemplo n.º 12
0
 def test_get_all_training_examples(self):
     processor = MongoProcessor()
     training_examples, ids = processor.get_all_training_examples("tests")
     assert training_examples
     assert ids
Exemplo n.º 13
0
 def test_load_from_path(self):
     processor = MongoProcessor()
     loop = asyncio.new_event_loop()
     assert (loop.run_until_complete(
         processor.save_from_path("tests/testing_data/initial", "tests",
                                  "testUser")) is None)
Exemplo n.º 14
0
 def test_get_stories(self):
     processor = MongoProcessor()
     stories = list(processor.get_stories("tests"))
     assert stories.__len__() == 6
Exemplo n.º 15
0
 def test_load_from_path(self):
     processor = MongoProcessor()
     assert (processor.save_from_path("tests/testing_data/initial", "tests",
                                      "testUser") is None)
Exemplo n.º 16
0
 def test_add_empty_training_example(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_training_example("", None, "tests", "testUser")
Exemplo n.º 17
0
 def test_load_from_path_error(self):
     processor = MongoProcessor()
     with pytest.raises(Exception):
         processor.save_from_path("tests/testing_data/error", "tests",
                                  "testUser")
Exemplo n.º 18
0
 def test_load_stories(self):
     processor = MongoProcessor()
     story_graph = processor.load_stories("tests")
     assert isinstance(story_graph, StoryGraph)
     assert story_graph.story_steps.__len__() == 5
Exemplo n.º 19
0
 def test_add_entity_duplicate(self):
     processor = MongoProcessor()
     with pytest.raises(Exception):
         assert processor.add_entity("file_text", "tests", "testUser")
Exemplo n.º 20
0
 def test_add_intent(self):
     processor = MongoProcessor()
     assert processor.add_intent("greeting", "tests", "testUser")
     intent = Intents.objects(bot="tests").get(name="greeting")
     assert intent.name == "greeting"
Exemplo n.º 21
0
 def test_add_action(self):
     processor = MongoProcessor()
     assert processor.add_action("utter_priority", "tests",
                                 "testUser") == None
     action = Actions.objects(bot="tests").get(name="utter_priority")
     assert action.name == "utter_priority"
Exemplo n.º 22
0
    StoryRequest,
    Endpoint,
    Config,
)
from bot_trainer.data_processor.data_objects import TrainingExamples, Responses
from bot_trainer.data_processor.processor import (
    MongoProcessor,
    AgentProcessor,
    ModelProcessor,
)
from bot_trainer.exceptions import AppException
from bot_trainer.train import start_training

router = APIRouter()
auth = Authentication()
mongo_processor = MongoProcessor()


@router.get("/intents", response_model=Response)
async def get_intents(current_user: User = Depends(auth.get_current_user)):
    """ This function returns the list of existing intents of the bot """
    return Response(
        data=mongo_processor.get_intents(current_user.get_bot())).dict()


@router.post("/intents", response_model=Response)
async def add_intents(request_data: TextData,
                      current_user: User = Depends(auth.get_current_user)):
    """ This function is used to add a new intent to the bot """
    id = mongo_processor.add_intent(text=request_data.data.strip(),
                                    bot=current_user.get_bot(),
Exemplo n.º 23
0
 def test_add_blank_action(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_action("  ", "tests", "testUser")
Exemplo n.º 24
0
 def test_add_intent_duplicate(self):
     processor = MongoProcessor()
     with pytest.raises(Exception):
         processor.add_intent("greeting", "tests", "testUser")
Exemplo n.º 25
0
 def test_add_blank_text_response(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_text_response("", "utter_happy", "tests", "testUser")
Exemplo n.º 26
0
 def test_add_none_intent(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_intent(None, "tests", "testUser")
Exemplo n.º 27
0
 def test_add_blank_response_name(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_text_response("Welcome", " ", "tests", "testUser")
Exemplo n.º 28
0
 def test_get_all_training_examples(self):
     processor = MongoProcessor()
     results = processor.get_all_training_examples("tests")
     assert results
Exemplo n.º 29
0
 def test_get_session_config(self):
     processor = MongoProcessor()
     session_config = processor.get_session_config("tests")
     assert session_config
     assert all(session_config[key]
                for key in ["sesssionExpirationTime", "carryOverSlots"])
Exemplo n.º 30
0
 def test_get_utterance_from_intent(self):
     processor = MongoProcessor()
     response = processor.get_utterance_from_intent("deny", "tests")
     print(response)
     assert response == "utter_goodbye"