opnform/app/Http/Controllers/Forms/AiFormController.php

38 lines
1.1 KiB
PHP
Raw Normal View History

2023-03-26 10:54:12 +00:00
<?php
namespace App\Http\Controllers\Forms;
use App\Console\Commands\GenerateTemplate;
use App\Http\Controllers\Controller;
use App\Http\Requests\AiGenerateFormRequest;
use App\Models\Forms\AI\AiFormCompletion;
2023-03-26 10:54:12 +00:00
use App\Service\OpenAi\GptCompleter;
use Illuminate\Support\Str;
class AiFormController extends Controller
{
public function generateForm(AiGenerateFormRequest $request)
{
$this->middleware('throttle:4,1');
return $this->success([
'message' => 'We\'re working on your form, please wait ~1 min.',
'ai_form_completion_id' => AiFormCompletion::create([
'form_prompt' => $request->input('form_prompt'),
'ip' => $request->ip()
])->id
2023-03-26 10:54:12 +00:00
]);
}
public function show(AiFormCompletion $aiFormCompletion)
2023-03-26 10:54:12 +00:00
{
if ($aiFormCompletion->ip != request()->ip()) {
return $this->error('You are not authorized to view this AI completion.', 403);
2023-03-26 10:54:12 +00:00
}
return $this->success([
'ai_form_completion' => $aiFormCompletion
]);
2023-03-26 10:54:12 +00:00
}
}