WIP
This commit is contained in:
parent
472b1a8061
commit
4bb2b59132
|
@ -130,6 +130,18 @@ class GenerateTemplate extends Command
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For the type "number" you can set the property "is_rating" to "true" to turn it into a star rating input.
|
||||||
|
|
||||||
|
If the form is too long, you can paginate it by adding a page break block in the list of properties:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name":"Page Break",
|
||||||
|
"next_btn_text":"Next",
|
||||||
|
"previous_btn_text":"Previous",
|
||||||
|
"type":"nf-page-break",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Give me the JSON code only, for the following form: "[REPLACE]"
|
Give me the JSON code only, for the following form: "[REPLACE]"
|
||||||
Do not ask me for more information about required properties or types, suggest me a form structure instead.
|
Do not ask me for more information about required properties or types, suggest me a form structure instead.
|
||||||
EOD;
|
EOD;
|
||||||
|
@ -163,27 +175,24 @@ class GenerateTemplate extends Command
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
// Get form structture
|
// Get form structture
|
||||||
$completer = new GptCompleter(config('services.openai.api_key'));
|
$completer = (new GptCompleter(config('services.openai.api_key')))
|
||||||
|
->setSystemMessage('You are a robot helping to generate forms.');
|
||||||
$completer->completeChat([
|
$completer->completeChat([
|
||||||
["role" => "system", "content" => "You are a robot helping to generate forms."],
|
|
||||||
["role" => "user", "content" => Str::of(self::FORM_STRUCTURE_PROMPT)->replace('[REPLACE]', $this->argument('prompt'))->toString()]
|
["role" => "user", "content" => Str::of(self::FORM_STRUCTURE_PROMPT)->replace('[REPLACE]', $this->argument('prompt'))->toString()]
|
||||||
],3000);
|
], 3000);
|
||||||
$formData = $completer->getArray();
|
$formData = $completer->getArray();
|
||||||
|
|
||||||
// Now get description and QAs
|
// Now get description and QAs
|
||||||
$formDescriptionPrompt = Str::of(self::FORM_DESCRIPTION_PROMPT)->replace('[REPLACE]', $this->argument('prompt'))->toString();
|
$formDescriptionPrompt = Str::of(self::FORM_DESCRIPTION_PROMPT)->replace('[REPLACE]', $this->argument('prompt'))->toString();
|
||||||
$formDescription = $completer->completeChat([
|
$formDescription = $completer->completeChat([
|
||||||
["role" => "system", "content" => "You are a robot helping to generate forms."],
|
|
||||||
["role" => "user", "content" => $formDescriptionPrompt]
|
["role" => "user", "content" => $formDescriptionPrompt]
|
||||||
])->getString();
|
])->getString();
|
||||||
$formQAs = $completer->completeChat([
|
$formQAs = $completer->completeChat([
|
||||||
["role" => "system", "content" => "You are a robot helping to generate forms."],
|
|
||||||
["role" => "user", "content" => $formDescriptionPrompt],
|
["role" => "user", "content" => $formDescriptionPrompt],
|
||||||
["role" => "assistant", "content" => $formDescription],
|
["role" => "assistant", "content" => $formDescription],
|
||||||
["role" => "user", "content" => self::FORM_QAS_PROMPT]
|
["role" => "user", "content" => self::FORM_QAS_PROMPT]
|
||||||
])->getArray();
|
])->getArray();
|
||||||
$formTitle = $completer->completeChat([
|
$formTitle = $completer->completeChat([
|
||||||
["role" => "system", "content" => "You are a robot helping to generate forms."],
|
|
||||||
["role" => "user", "content" => $formDescriptionPrompt],
|
["role" => "user", "content" => $formDescriptionPrompt],
|
||||||
["role" => "assistant", "content" => $formDescription],
|
["role" => "assistant", "content" => $formDescription],
|
||||||
["role" => "user", "content" => self::FORM_TITLE_PROMPT]
|
["role" => "user", "content" => self::FORM_TITLE_PROMPT]
|
||||||
|
@ -191,7 +200,6 @@ class GenerateTemplate extends Command
|
||||||
|
|
||||||
// Finally get keyworks for image cover
|
// Finally get keyworks for image cover
|
||||||
$formCoverKeyworks = $completer->completeChat([
|
$formCoverKeyworks = $completer->completeChat([
|
||||||
["role" => "system", "content" => "You are a robot helping to generate forms."],
|
|
||||||
["role" => "user", "content" => $formDescriptionPrompt],
|
["role" => "user", "content" => $formDescriptionPrompt],
|
||||||
["role" => "assistant", "content" => $formDescription],
|
["role" => "assistant", "content" => $formDescription],
|
||||||
["role" => "user", "content" => self::FORM_IMG_KEYWORDS_PROMPT]
|
["role" => "user", "content" => self::FORM_IMG_KEYWORDS_PROMPT]
|
||||||
|
@ -225,6 +233,9 @@ class GenerateTemplate extends Command
|
||||||
$property['id'] = Str::uuid()->toString();
|
$property['id'] = Str::uuid()->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean data
|
||||||
|
$formTitle = Str::of($formTitle)->replace('"', '')->toString();
|
||||||
|
|
||||||
return Template::create([
|
return Template::create([
|
||||||
'name' => $formTitle,
|
'name' => $formTitle,
|
||||||
'description' => $formDescription,
|
'description' => $formDescription,
|
||||||
|
|
|
@ -8,8 +8,6 @@ class SpaController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get the SPA view.
|
* Get the SPA view.
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
*/
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,11 +92,11 @@ class GptCompleter
|
||||||
|
|
||||||
protected function computeChatCompletion(array $messages, int $maxTokens = 512, float $temperature = 0.81): self
|
protected function computeChatCompletion(array $messages, int $maxTokens = 512, float $temperature = 0.81): self
|
||||||
{
|
{
|
||||||
if (isset($this->systemMessage)) {
|
if (isset($this->systemMessage) && $messages[0]['role'] !== 'system') {
|
||||||
$messages = array_merge([
|
$messages = array_merge([[
|
||||||
'role' => 'system',
|
'role' => 'system',
|
||||||
'content' => $this->systemMessage
|
'content' => $this->systemMessage
|
||||||
], $messages);
|
]], $messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
$completionInput = [
|
$completionInput = [
|
||||||
|
|
|
@ -178,7 +178,7 @@ class SeoMetaResolver
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => $template->name . $this->titleSuffix(),
|
'title' => $template->name . $this->titleSuffix(),
|
||||||
'description' => Str::of($template->description)->limit(160) ,
|
'description' => Str::of($template->description)->limit(160),
|
||||||
'image' => $template->image_url
|
'image' => $template->image_url
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue