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]
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 = <<<EOD
@ -192,8 +192,8 @@ class GenerateTemplate extends Command
Here are the only types you can choose from: [TYPES]
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.
Ex: ["consent_forms","award_forms"]
Reply only with a valid JSON array, being an array of string. Order assigned types from the most relevant to the less relevant.
Ex: { "types": ["consent_forms","award_forms"]}
EOD;
const FORM_QAS_PROMPT = <<<EOD
@ -228,7 +228,7 @@ class GenerateTemplate extends Command
->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) {

View File

@ -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)