From f7b6411383aefb2f8d94a66815bfd8a449e77a4d Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Tue, 30 Jan 2024 12:32:33 +0100 Subject: [PATCH] Fix template generation using gpt4 --- app/Console/Commands/GenerateTemplate.php | 15 ++++++++------- client/stores/templates.js | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/GenerateTemplate.php b/app/Console/Commands/GenerateTemplate.php index 6e5e2ae..716aa09 100644 --- a/app/Console/Commands/GenerateTemplate.php +++ b/app/Console/Commands/GenerateTemplate.php @@ -181,8 +181,8 @@ class GenerateTemplate extends Command Here are the only industries you can choose from: [INDUSTRIES] Do no make up any new type, only use the ones listed above. - Reply only with a valid JSON, being an array of string. Order assigned industries from the most relevant to the less relevant. - Ex: ["banking_forms","customer_service_forms"] + Reply only with a valid JSON array, being an array of string. Order assigned industries from the most relevant to the less relevant. + Ex: { "industries": ["banking_forms","customer_service_forms"]} EOD; const FORM_TYPES_PROMPT = <<setSystemMessage('You are an assistant helping to generate forms.'); $completer->expectsJson()->completeChat([ ["role" => "user", "content" => Str::of(self::FORM_STRUCTURE_PROMPT)->replace('[REPLACE]', $this->argument('prompt'))->toString()] - ], 6000); + ]); $formData = $completer->getArray(); $completer->doesNotExpectJson(); @@ -315,7 +315,7 @@ class GenerateTemplate extends Command ->replace('[REPLACE]', $formPrompt) ->replace('[INDUSTRIES]', $industriesString) ->toString()] - ])->getArray(); + ])->getArray()['industries']; } private function getTypes(GptCompleter $completer, string $formPrompt): array @@ -326,11 +326,12 @@ class GenerateTemplate extends Command ->replace('[REPLACE]', $formPrompt) ->replace('[TYPES]', $typesString) ->toString()] - ])->getArray(); + ])->getArray()['types']; } private function getRelatedTemplates(array $industries, array $types): array { + ray($industries, $types); $templateScore = []; Template::chunk(100, function ($otherTemplates) use ($industries, $types, &$templateScore) { foreach ($otherTemplates as $otherTemplate) { diff --git a/client/stores/templates.js b/client/stores/templates.js index 4dd1e90..10ecdcf 100644 --- a/client/stores/templates.js +++ b/client/stores/templates.js @@ -13,11 +13,13 @@ export const useTemplatesStore = defineStore('templates', () => { const types = ref(new Map) const getTemplateTypes = (slugs) => { + if (!slugs) return [] return slugs.map((slug) => { return types.value.get(slug) }).filter((item) => item !== undefined) } const getTemplateIndustries = (slugs) => { + if (!slugs) return [] return slugs.map((slug) => { return industries.value.get(slug) }).filter((item) => item !== undefined)