This commit is contained in:
Julien Nahum 2023-03-23 14:07:55 +01:00
parent 472b1a8061
commit 4bb2b59132
4 changed files with 22 additions and 13 deletions

View File

@ -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]"
Do not ask me for more information about required properties or types, suggest me a form structure instead.
EOD;
@ -163,9 +175,9 @@ class GenerateTemplate extends Command
public function handle()
{
// 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([
["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()]
], 3000);
$formData = $completer->getArray();
@ -173,17 +185,14 @@ class GenerateTemplate extends Command
// Now get description and QAs
$formDescriptionPrompt = Str::of(self::FORM_DESCRIPTION_PROMPT)->replace('[REPLACE]', $this->argument('prompt'))->toString();
$formDescription = $completer->completeChat([
["role" => "system", "content" => "You are a robot helping to generate forms."],
["role" => "user", "content" => $formDescriptionPrompt]
])->getString();
$formQAs = $completer->completeChat([
["role" => "system", "content" => "You are a robot helping to generate forms."],
["role" => "user", "content" => $formDescriptionPrompt],
["role" => "assistant", "content" => $formDescription],
["role" => "user", "content" => self::FORM_QAS_PROMPT]
])->getArray();
$formTitle = $completer->completeChat([
["role" => "system", "content" => "You are a robot helping to generate forms."],
["role" => "user", "content" => $formDescriptionPrompt],
["role" => "assistant", "content" => $formDescription],
["role" => "user", "content" => self::FORM_TITLE_PROMPT]
@ -191,7 +200,6 @@ class GenerateTemplate extends Command
// Finally get keyworks for image cover
$formCoverKeyworks = $completer->completeChat([
["role" => "system", "content" => "You are a robot helping to generate forms."],
["role" => "user", "content" => $formDescriptionPrompt],
["role" => "assistant", "content" => $formDescription],
["role" => "user", "content" => self::FORM_IMG_KEYWORDS_PROMPT]
@ -225,6 +233,9 @@ class GenerateTemplate extends Command
$property['id'] = Str::uuid()->toString();
}
// Clean data
$formTitle = Str::of($formTitle)->replace('"', '')->toString();
return Template::create([
'name' => $formTitle,
'description' => $formDescription,

View File

@ -8,8 +8,6 @@ class SpaController extends Controller
{
/**
* Get the SPA view.
*
* @return \Illuminate\Http\Response
*/
public function __invoke(Request $request)
{

View File

@ -92,11 +92,11 @@ class GptCompleter
protected function computeChatCompletion(array $messages, int $maxTokens = 512, float $temperature = 0.81): self
{
if (isset($this->systemMessage)) {
$messages = array_merge([
if (isset($this->systemMessage) && $messages[0]['role'] !== 'system') {
$messages = array_merge([[
'role' => 'system',
'content' => $this->systemMessage
], $messages);
]], $messages);
}
$completionInput = [