Looking to hire Laravel developers? Try LaraJobs

laravel-openai-moderation maintained by rcerljenko

Description
Laravel package for OpenAI Moderation API
Last update
2023/02/27 16:19 (dev-main)
License
Downloads
1 254

Comments
comments powered by Disqus

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

  1. Publish config and translation files.
php artisan vendor:publish --provider="RCerljenko\LaravelOpenAIModeration\ServiceProvider"
  1. Set your OpenAI API key and enable package via newly created config file => config/openai.php

  2. 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],
  ];
 }
}