LaravelSklearnBot is a Laravel package that allows you to parse data, create and train models, and use them to generate responses to requests.
- Install the required dependencies:
pip install flask scikit-learn python-dotenv
- Add
LaravelSklearnBot
to yourcomposer.json
and run the following command:
composer require dog729/laravel-sklearnbot
To use the package, invoke the following methods from the SklearnbotFacade
:
-
Parse data with training:
\LaravelSklearnBot\SklearnbotFacade::parserHelpBotModel();
-
Retrain the model from scratch:
\LaravelSklearnBot\SklearnbotFacade::trainModelFromScratch();
-
Get a response from the model based on a query:
$result = \LaravelSklearnBot\SklearnbotFacade::getHelpBotResponse('hi'); print_r($result);
-
Fine-tune the model:
\LaravelSklearnBot\SklearnbotFacade::fineTuneModelHelpBot([ [ 'id' => 8, 'type' => 'sw', 'title' => 'Darth Vader', 'text' => 'Anakin pam pam', ] ]); $result = \LaravelSklearnBot\SklearnbotFacade::getHelpBotResponse('Darth Vader'); print_r($result); // Returns: Array ( [action] => Array ( ) [id] => 8 [text] => Anakin pam pam [type] => sw )
-
Create a helpbot model handler file:
php artisan make:helpbotmodel {name}
-
Install the package and generate necessary files:
php artisan helpbot:install
This command will install the package, generate a token, and create the
helpbot.py
file.
The configuration file config/sklearnbot.php
contains the following parameters:
return [
/**
* Logic for the operation of submodules
*/
'helpbot' => 'python',
'python' => [
'run' => 'app.py',
/**
* host:port for the running Flask application
*/
'helpbot_token' => ENV('HELPBOT_TOKEN'),
'helpbot_host' => ENV('HELPBOT_FLASK_HOST',"127.0.0.1"),
'helpbot_port' => ENV('HELPBOT_FLASK_PORT',"5729"),
/**
* The name of the model files
*/
'helpbot_model' => 'helpbot',
'helpbot_model_addtraining' => true, //auto further training of the model
'helpbot_pkl' => ENV('HELPBOT_PKL','model.pkl'), //model helpbot
'helpbot_output_pkl' => ENV('HELPBOT_OUTPUT_PKL','output.pkl'), //model helpbot database
],
];
Examples for testing with curl
:
-
Create a model:
curl -X POST http://127.0.0.1:5729/create-model -H "Content-Type: application/json" -H "Authorization: your-secure-token"
-
Reload the model:
curl -X POST http://127.0.0.1:5729/reload-model -H "Content-Type: application/json" -H "Authorization: your-secure-token"
-
Fine-tune the model:
curl -X POST http://127.0.0.1:5729/fine-tune-model -H "Content-Type: application/json" -H "Authorization: your-secure-token" -d '[{"id":"3","title":"boba","text":"aboba"}]'
-
Get a response:
curl -X POST http://127.0.0.1:5729/get-response -H "Content-Type: application/json" -d '{"text":"boba"}'