PHP code example of byte5 / ai-entry-embeddings
1. Go to this page and download the library: Download byte5/ai-entry-embeddings library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
byte5 / ai-entry-embeddings example snippets
'collections' => [
'pages' => [
'fields' => ['title', 'page_builder'],
],
'blog' => [
'fields' => ['title', 'content'],
],
],
'collections' => [
'pages' => [
'fields' => [
'title',
'custom_field' => [\App\Extractors\MyCustomExtractor::class],
],
],
],
'embeddings' => [
'dimensions' => 1536,
],
'only_published' => true,
use Byte5\AiEntryEmbeddings\Pipelines\Extraction\ContentChunk;
use Byte5\AiEntryEmbeddings\Pipelines\Extraction\Contracts\FieldExtractorInterface;
use Statamic\Entries\Entry as StatamicEntry;
use Statamic\Fields\Field;
class ExtractMyField implements FieldExtractorInterface
{
public function extract(
StatamicEntry $entry,
string $fieldHandle,
mixed $value,
Field $field,
string $parentPath = '',
): array {
$path = $parentPath !== '' ? "{$parentPath}.{$fieldHandle}" : $fieldHandle;
return [
new ContentChunk(
text: (string) $value,
fieldHandle: $fieldHandle,
path: $path,
metadata: ['field_handle' => $fieldHandle],
),
];
}
}
'default_field_extractors' => [
'my_type' => \App\Extractors\ExtractMyField::class,
],
'collections' => [
'pages' => [
'fields' => [
'my_field' => [\App\Extractors\ExtractMyField::class],
],
],
],
bash
php artisan vendor:publish --tag=config --provider="Byte5\AiEntryEmbeddings\ServiceProvider"
bash
php artisan migrate