Skip to content
Snippets Groups Projects

Check entity can be loaded before creating snippet.

Closed Mark Jones requested to merge bugfix/entity-check into 1.0.x
1 file
+ 8
6
Compare changes
  • Side-by-side
  • Inline
+ 8
6
@@ -133,12 +133,14 @@ class ChatForm extends FormBase {
continue;
}
$entity = $index->loadItem($match->getExtraData('metadata')->item_id)->getValue();
$content = StringHelper::prepareText(trim($match->getExtraData('metadata')->content), [], 1024);
$messages[] = [
'role' => 'system',
'content' => "Source link: {$entity->toLink()->toString()}\nSnippet: {$content}",
];
// If the entity can be loaded, prepare a trimmed version
if ($entity = $index->loadItem($match->getExtraData('metadata')->item_id)->getValue()) {
$content = StringHelper::prepareText(trim($match->getExtraData('metadata')->content), [], 1024);
$messages[] = [
'role' => 'system',
'content' => "Source link: {$entity->toLink()->toString()}\nSnippet: {$content}",
];
}
}
// Send the query to OpenAI.
Loading