Import & Export Model

In production, you don’t want to train your chatbot all the time. That's why Chatman allows you to import and export your train models. You can use exportModel() method of BotWithPatterns and BotWithoutPatterns classes.


        
    require_once __DIR__ . '/vendor/autoload.php';

    use Chatman\BotWithPatterns;

    $bot = new BotWithPatterns("chatbot.json");
    $bot->train();

    //Make sure that the path is not write protected !
    $bot->exportModel("/path/model");

    $resp = $bot->getResponse("hello");

    echo $resp['resp'];

      

Import if trained else train & export


        
    require_once __DIR__ . '/vendor/autoload.php';

    use Chatman\BotWithPatterns;

    $bot = new BotWithPatterns("chatbot.json");

    $modelPath = "/path/chatbot-model";

    if(file_exists($modelPath)){
        $bot->importModel($modelPath);
    }else{
        $bot->train();
        $bot->exportModel($modelPath);
    }

    $resp = $bot->getResponse("hello");

    echo $resp['resp'];

      

NOTE : Do not remove the json file after exporting the model !