Download the PHP package jpcaparas/laravel-faker-openai without Composer
On this page you can find all versions of the php package jpcaparas/laravel-faker-openai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jpcaparas/laravel-faker-openai
More information about jpcaparas/laravel-faker-openai
Files in jpcaparas/laravel-faker-openai
Package laravel-faker-openai
Short Description An opinionated Laravel package that modifies the service container Faker behaviour to allow prompts to be generated with OpenAI
License MIT
Informations about the package laravel-faker-openai
Laravel Faker OpenAI Provider
A Laravel package that extends FakerPHP by adding an AI-powered data generator using OpenAI. This allows you to generate more realistic and context-aware fake data in your Laravel applications.
Installation
Install the package via Composer:
The package will automatically register its service provider if you're using Laravel's package auto-discovery.
Configuration
- Next, execute the install command:
This will create a config/openai.php
configuration file in your project, which you can modify to your needs using environment variables.
-
Make sure you have your OpenAI API key set in your
.env
file: - The package uses
gpt-3.5-turbo
model by default.
Usage
The package adds a new promptAI()
method to the Faker generator. You can use it in several ways:
Basic Usage
... you can also use the built-in fake()
helper:
With Fallback Values
You can provide fallback values that will be used if the AI request fails:
Error Handling
By default, errors are logged and the fallback value is returned. You can make it throw exceptions instead:
How It Works
The package works by:
- Intercepting FakerPHP method calls through a prompt
- Sending them to OpenAI's GPT model
- Returning AI-generated responses that match FakerPHP's expected output format
Testing
Run the test suite:
License
MIT
All versions of laravel-faker-openai with dependencies
fakerphp/faker Version ^1.24
laravel/framework Version ^10.0 || ^11.0
nyholm/psr7 Version ^1.8
openai-php/laravel Version ^0.10.2
symfony/http-client Version ^7.2