Skip to content

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.

License

ahmedash95/sentimento

Repository files navigation

Sentimento

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.

Laravel Version GitHub Workflow Status (master) Total Downloads Latest Version License

logo

use Ahmedash95\Sentimento\Facade\Sentimento;

$result = Sentimento::analyze("Food was great!");

$result->value; // Positive

Installation

  • 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

Usage

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

⚠️⚠️⚠️ When calling OpenAI to analyze text, there is a possibility that HTTP exceptions may occur if the request to OpenAI fails. This can happen due to a variety of reasons, such as network connectivity issues, server errors, or even rate limiting policies imposed by OpenAI. If the request to OpenAI fails, the package may not be able to properly analyze the sentiment of the given text and may result in unexpected errors or output. To handle this, it is important to catch and handle any potential HTTP exceptions that may occur

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

Testing

composer test

Contributing

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages