[Laravel 扩展包]ChatGPT 模拟 API 生成器 - Laravel
ChatGPT 模拟 API 生成器 Laravel 扩展包使用 ChatGPT prompt 在 Laravel 中生成智能 API 模拟:
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,
);
});
以上代码将会生成如下 JSON 响应:
[
{
"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."
}
]
为了避免 API 限制(而且可能改进后续请求的表现),该包默认缓存了生成的响应。
该包也提供了其他一些特性,比如禁用前述的缓存及配置 ChatGPT 模型。
你可以在 Github 上了解更多详情。