Fix template generation using gpt4

This commit is contained in:
Julien Nahum 2024-01-30 12:32:33 +01:00
parent 7348605327
commit f7b6411383
2 changed files with 10 additions and 7 deletions

View File

@ -181,8 +181,8 @@ class GenerateTemplate extends Command
Here are the only industries you can choose from: [INDUSTRIES] Here are the only industries you can choose from: [INDUSTRIES]
Do no make up any new type, only use the ones listed above. 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. Reply only with a valid JSON array, being an array of string. Order assigned industries from the most relevant to the less relevant.
Ex: ["banking_forms","customer_service_forms"] Ex: { "industries": ["banking_forms","customer_service_forms"]}
EOD; EOD;
const FORM_TYPES_PROMPT = <<<EOD const FORM_TYPES_PROMPT = <<<EOD
@ -192,8 +192,8 @@ class GenerateTemplate extends Command
Here are the only types you can choose from: [TYPES] Here are the only types you can choose from: [TYPES]
Do no make up any new type, only use the ones listed above. 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 types from the most relevant to the less relevant. Reply only with a valid JSON array, being an array of string. Order assigned types from the most relevant to the less relevant.
Ex: ["consent_forms","award_forms"] Ex: { "types": ["consent_forms","award_forms"]}
EOD; EOD;
const FORM_QAS_PROMPT = <<<EOD const FORM_QAS_PROMPT = <<<EOD
@ -228,7 +228,7 @@ class GenerateTemplate extends Command
->setSystemMessage('You are an assistant helping to generate forms.'); ->setSystemMessage('You are an assistant helping to generate forms.');
$completer->expectsJson()->completeChat([ $completer->expectsJson()->completeChat([
["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()]
], 6000); ]);
$formData = $completer->getArray(); $formData = $completer->getArray();
$completer->doesNotExpectJson(); $completer->doesNotExpectJson();
@ -315,7 +315,7 @@ class GenerateTemplate extends Command
->replace('[REPLACE]', $formPrompt) ->replace('[REPLACE]', $formPrompt)
->replace('[INDUSTRIES]', $industriesString) ->replace('[INDUSTRIES]', $industriesString)
->toString()] ->toString()]
])->getArray(); ])->getArray()['industries'];
} }
private function getTypes(GptCompleter $completer, string $formPrompt): array private function getTypes(GptCompleter $completer, string $formPrompt): array
@ -326,11 +326,12 @@ class GenerateTemplate extends Command
->replace('[REPLACE]', $formPrompt) ->replace('[REPLACE]', $formPrompt)
->replace('[TYPES]', $typesString) ->replace('[TYPES]', $typesString)
->toString()] ->toString()]
])->getArray(); ])->getArray()['types'];
} }
private function getRelatedTemplates(array $industries, array $types): array private function getRelatedTemplates(array $industries, array $types): array
{ {
ray($industries, $types);
$templateScore = []; $templateScore = [];
Template::chunk(100, function ($otherTemplates) use ($industries, $types, &$templateScore) { Template::chunk(100, function ($otherTemplates) use ($industries, $types, &$templateScore) {
foreach ($otherTemplates as $otherTemplate) { foreach ($otherTemplates as $otherTemplate) {

View File

@ -13,11 +13,13 @@ export const useTemplatesStore = defineStore('templates', () => {
const types = ref(new Map) const types = ref(new Map)
const getTemplateTypes = (slugs) => { const getTemplateTypes = (slugs) => {
if (!slugs) return []
return slugs.map((slug) => { return slugs.map((slug) => {
return types.value.get(slug) return types.value.get(slug)
}).filter((item) => item !== undefined) }).filter((item) => item !== undefined)
} }
const getTemplateIndustries = (slugs) => { const getTemplateIndustries = (slugs) => {
if (!slugs) return []
return slugs.map((slug) => { return slugs.map((slug) => {
return industries.value.get(slug) return industries.value.get(slug)
}).filter((item) => item !== undefined) }).filter((item) => item !== undefined)