Skip to content

Commit f7b6411

Browse files
committed
Fix template generation using gpt4
1 parent 7348605 commit f7b6411

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

app/Console/Commands/GenerateTemplate.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ class GenerateTemplate extends Command
181181
Here are the only industries you can choose from: [INDUSTRIES]
182182
Do no make up any new type, only use the ones listed above.
183183
184-
Reply only with a valid JSON, being an array of string. Order assigned industries from the most relevant to the less relevant.
185-
Ex: ["banking_forms","customer_service_forms"]
184+
Reply only with a valid JSON array, being an array of string. Order assigned industries from the most relevant to the less relevant.
185+
Ex: { "industries": ["banking_forms","customer_service_forms"]}
186186
EOD;
187187

188188
const FORM_TYPES_PROMPT = <<<EOD
@@ -192,8 +192,8 @@ class GenerateTemplate extends Command
192192
Here are the only types you can choose from: [TYPES]
193193
Do no make up any new type, only use the ones listed above.
194194
195-
Reply only with a valid JSON, being an array of string. Order assigned types from the most relevant to the less relevant.
196-
Ex: ["consent_forms","award_forms"]
195+
Reply only with a valid JSON array, being an array of string. Order assigned types from the most relevant to the less relevant.
196+
Ex: { "types": ["consent_forms","award_forms"]}
197197
EOD;
198198

199199
const FORM_QAS_PROMPT = <<<EOD
@@ -228,7 +228,7 @@ public function handle()
228228
->setSystemMessage('You are an assistant helping to generate forms.');
229229
$completer->expectsJson()->completeChat([
230230
["role" => "user", "content" => Str::of(self::FORM_STRUCTURE_PROMPT)->replace('[REPLACE]', $this->argument('prompt'))->toString()]
231-
], 6000);
231+
]);
232232
$formData = $completer->getArray();
233233

234234
$completer->doesNotExpectJson();
@@ -315,7 +315,7 @@ private function getIndustries(GptCompleter $completer, string $formPrompt): arr
315315
->replace('[REPLACE]', $formPrompt)
316316
->replace('[INDUSTRIES]', $industriesString)
317317
->toString()]
318-
])->getArray();
318+
])->getArray()['industries'];
319319
}
320320

321321
private function getTypes(GptCompleter $completer, string $formPrompt): array
@@ -326,11 +326,12 @@ private function getTypes(GptCompleter $completer, string $formPrompt): array
326326
->replace('[REPLACE]', $formPrompt)
327327
->replace('[TYPES]', $typesString)
328328
->toString()]
329-
])->getArray();
329+
])->getArray()['types'];
330330
}
331331

332332
private function getRelatedTemplates(array $industries, array $types): array
333333
{
334+
ray($industries, $types);
334335
$templateScore = [];
335336
Template::chunk(100, function ($otherTemplates) use ($industries, $types, &$templateScore) {
336337
foreach ($otherTemplates as $otherTemplate) {

client/stores/templates.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ export const useTemplatesStore = defineStore('templates', () => {
1313
const types = ref(new Map)
1414

1515
const getTemplateTypes = (slugs) => {
16+
if (!slugs) return []
1617
return slugs.map((slug) => {
1718
return types.value.get(slug)
1819
}).filter((item) => item !== undefined)
1920
}
2021
const getTemplateIndustries = (slugs) => {
22+
if (!slugs) return []
2123
return slugs.map((slug) => {
2224
return industries.value.get(slug)
2325
}).filter((item) => item !== undefined)

0 commit comments

Comments
 (0)