laravel-openai-moderation maintained by rcerljenko
Description
Laravel package for OpenAI Moderation API
Author
Last update
2023/02/27 16:19
(dev-main)
License
Downloads
1 254
Laravel OpenAI Moderation Rule
Laravel validation Rule using OpenAI Moderation API. Gives you a way to validate your form requests for inappropriate content.
Installation
Standard Composer package installation:
composer require rcerljenko/laravel-openai-moderation
Usage
- Publish config and translation files.
php artisan vendor:publish --provider="RCerljenko\LaravelOpenAIModeration\ServiceProvider"
-
Set your OpenAI API key and enable package via newly created config file =>
config/openai.php -
Use provided rule with your validation rules.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use RCerljenko\LaravelOpenAIModeration\Rules\OpenAIModeration;
class StoreText extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'text' => ['required', 'string', new OpenAIModeration],
];
}
}