Fix AI generation + remove valet tls
This commit is contained in:
parent
b043407a4f
commit
8e5acab8bf
|
@ -3,11 +3,9 @@
|
||||||
namespace App\Jobs\Form;
|
namespace App\Jobs\Form;
|
||||||
|
|
||||||
use App\Console\Commands\GenerateTemplate;
|
use App\Console\Commands\GenerateTemplate;
|
||||||
use App\Http\Requests\AiGenerateFormRequest;
|
|
||||||
use App\Models\Forms\AI\AiFormCompletion;
|
use App\Models\Forms\AI\AiFormCompletion;
|
||||||
use App\Service\OpenAi\GptCompleter;
|
use App\Service\OpenAi\GptCompleter;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
@ -40,6 +38,7 @@ class GenerateAiForm implements ShouldQueue
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$completer = (new GptCompleter(config('services.openai.api_key')))
|
$completer = (new GptCompleter(config('services.openai.api_key')))
|
||||||
|
->useStreaming()
|
||||||
->setSystemMessage('You are a robot helping to generate forms.');
|
->setSystemMessage('You are a robot helping to generate forms.');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -53,29 +52,11 @@ class GenerateAiForm implements ShouldQueue
|
||||||
'result' => $this->cleanOutput($completer->getArray())
|
'result' => $this->cleanOutput($completer->getArray())
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->completion->update([
|
$this->onError($e);
|
||||||
'status' => AiFormCompletion::STATUS_FAILED,
|
|
||||||
'result' => ['error' => $e->getMessage()]
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateForm(AiGenerateFormRequest $request)
|
|
||||||
{
|
|
||||||
$completer = (new GptCompleter(config('services.openai.api_key')))
|
|
||||||
->setSystemMessage('You are a robot helping to generate forms.');
|
|
||||||
$completer->completeChat([
|
|
||||||
["role" => "user", "content" => Str::of(GenerateTemplate::FORM_STRUCTURE_PROMPT)
|
|
||||||
->replace('[REPLACE]', $request->form_prompt)->toString()]
|
|
||||||
], 3000);
|
|
||||||
|
|
||||||
return $this->success([
|
|
||||||
'message' => 'Form successfully generated!',
|
|
||||||
'form' => $this->cleanOutput($completer->getArray())
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function cleanOutput($formData)
|
private function cleanOutput($formData)
|
||||||
{
|
{
|
||||||
// Add property uuids
|
// Add property uuids
|
||||||
|
@ -85,4 +66,19 @@ class GenerateAiForm implements ShouldQueue
|
||||||
|
|
||||||
return $formData;
|
return $formData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a job failure.
|
||||||
|
*/
|
||||||
|
public function failed(\Throwable $exception): void
|
||||||
|
{
|
||||||
|
$this->onError($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onError(\Throwable $e) {
|
||||||
|
$this->completion->update([
|
||||||
|
'status' => AiFormCompletion::STATUS_FAILED,
|
||||||
|
'result' => ['error' => $e->getMessage()]
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,7 @@ const plugins = [
|
||||||
laravel({
|
laravel({
|
||||||
input: [
|
input: [
|
||||||
'resources/js/app.js'
|
'resources/js/app.js'
|
||||||
],
|
]
|
||||||
valetTls: 'opnform.test'
|
|
||||||
}),
|
}),
|
||||||
vue({
|
vue({
|
||||||
template: {
|
template: {
|
||||||
|
|
Loading…
Reference in New Issue