A laravel package that provides sentiment analysis capabilities using OpenAI's GPT to easily analyze text-based data and gain insight into the underlying sentiment.
use Ahmedash95\Sentimento\Facade\Sentimento;
$result = Sentimento::analyze("Food was great!");
$result->value; // Positive
- First you need to install the package using composer
composer require ahmedash95/sentimento
- (Optional) Publish config file
php artisan vendor:publish --tag="sentimento-config"
- Add your OpenAI API key to your .env file
SENTIMENTO_OPENAI_TOKEN=sk-xxxxxxxxxxxxxxxxxxxx
Now you are ready to use the package
OpenAI can comprehend multiple languages, and using it is as easy as invoking a function.
use Ahmedash95\Sentimento\Facade\Sentimento;
Sentimento::analyze("Food was great!"); // Positive
Sentimento::analyze("Food was bad!"); // Negative
Sentimento::analyze("لما اتصلت بالدليفري قالي انه اكل الاوردر"); // Negative
use Ahmedash95\Sentimento\Facade\Sentimento;
use Illuminate\Http\Client\RequestException;
try {
$result = Sentimento::analyze("Food was great!");
} catch (RequestException $e) {
// $e->getMessage()
}
Or you can set the report_failures
option to false
in the config file to disable reporting failures
// instead of exception, the result will be Decision::Unknown
$result = Sentimento::analyze("Food was great!"); // Unknown
composer test
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
The MIT License (MIT). Please see License File for more information.