ChatGPT Mock API Generator for Laravel

Packages

July 5th, 2023

ChatGPT Mock API Generator for Laravel

The ChatGPT Mock API Generator package for Laravel generates smart API mocks in Laravel using ChatGPT prompts:

use YellowDigital\LaravelChatgptMockApi\Facades\ChatGPTMockApi;
 
Route::get("/mock-response", function() {
return ChatGPTMockApi::generate(
prompt: "European countries and their national food",
keys: [
"id",
"name",
"food",
"food_description",
],
count: 3,
);
});

Which would generate the following JSON response:

[
{
"id": 1,
"name": "Italy",
"food": "Pizza",
"food_description": "A delicious round dough topped with tomato sauce, cheese and a variety of toppings."
},
{
"id": 2,
"name": "France",
"food": "Croissants",
"food_description": "A flaky, buttery pastry that is commonly eaten for breakfast or as a snack."
},
{
"id": 3,
"name": "Spain",
"food": "Paella",
"food_description": "A rice dish that originated in Valencia and is typically made with saffron, chicken, and shellfish."
}
]

To avoid hitting API limits (and perhaps improving performance on subsequent requests), by default, this package caches generated responses.

At the time of writing, this package also offers a few other features, like disabling the aforementioned cache and configuring the ChatGPT model used with the prompt.

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.