sfolador/ai-avatar-suggest

Create avatar for your users with openai

1.2 2023-02-22 20:02 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Use this library to generate avatars for your users by letting them insert a short description about themselves.

Installation

You can install the package via composer:

composer require sfolador/ai-avatar-suggest

You can publish the config file with:

php artisan vendor:publish --tag="ai-avatar-suggest-config"

This is the contents of the published config file:

return [
    'openai_key' => env('OPENAI_KEY'),
    'default_size' => '256x256',
    'default_route' => 'ai-avatar-suggest',
    'use_cache' => true,
    'throttle' => [
        'enabled' => false,
        'max_attempts' => 60,
        'prefix' => 'ai-avatar-suggest',
    ],
];

Remember to set your OpenAI key in your .env file.

If the use_cache option is set to true, the package will use the default cache driver to prevent unnecessary calls to the OpenAI API. You can change the cache driver in your config/cache.php file.

Usage

$aiAvatarSuggest = new Sfolador\AiAvatarSuggest();
echo $aiAvatarSuggest->suggest('A developer with a red beard and a cool hat');

//or if you want to use the facade

echo AiAvatarSuggest::suggest('A developer with a red beard and a cool hat');

You can also invoke the generation by calling the route ai-avatar-suggest with a prompt parameter. The response will be a JSON with the suggested email, such as:

{
  "suggestion": "https://www.example.com/link/to/avatar"
}

Cache clear

If you use a Cache driver that supports tags, you can clear the cache by invoking the command:

php artisan ai-avatar-suggest:clear-cache

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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