Bộ tạo ChatGPT Mock API cho Laravel
ChatGPT Mock API Generator package cho Laravel tạo ra các bản mô phỏng API thông minh trong Laravel bằng cách sử dụng câu gợi ý từ ChatGPT.
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,
);
});
Điều này sẽ tạo ra JSON response sau đây:
[
{
"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."
}
]
Để tránh vượt quá giới hạn API (và có thể cải thiện hiệu suất trên các yêu cầu sau đó), theo mặc định, gói này lưu trữ bộ nhớ cache các phản hồi đã tạo.
Tại thời điểm viết, gói này cũng cung cấp một số tính năng khác như tắt bộ nhớ cache nêu trên và cấu hình ChatGPT Model được sử dụng với câu gợi.
Bạn có thể tìm hiểu thêm về gói này, xem hướng dẫn cài đặt đầy đủ và xem source code trên GitHub.