Laravel validation Rule using OpenAI Moderation API. Gives you a way to validate your form requests for inappropriate content.
Standard Composer package installation:
composer require rcerljenko/laravel-openai-moderation
- 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],
];
}
}