mirror of
https://github.com/symfony/ai.git
synced 2026-03-23 23:42:18 +01:00
32 lines
1.0 KiB
PHP
32 lines
1.0 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
|
|
use Symfony\AI\Store\Document\TextDocument;
|
|
use Symfony\AI\Store\Document\VectorDocument;
|
|
use Symfony\AI\Store\Document\Vectorizer;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
require_once dirname(__DIR__).'/bootstrap.php';
|
|
|
|
$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
|
|
|
|
$textDocuments = [
|
|
new TextDocument(Uuid::v4(), 'Hello World'),
|
|
new TextDocument(Uuid::v4(), 'Lorem ipsum dolor sit amet'),
|
|
new TextDocument(Uuid::v4(), 'PHP Hypertext Preprocessor'),
|
|
];
|
|
|
|
$vectorizer = new Vectorizer($platform, 'text-embedding-3-large');
|
|
$vectorDocuments = $vectorizer->vectorize($textDocuments);
|
|
|
|
dump(array_map(static fn (VectorDocument $document) => $document->getVector()->getDimensions(), $vectorDocuments));
|