Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/openai/pdf-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Symfony\AI\Agent\Agent;
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
use Symfony\AI\Platform\Message\Content\File;
use Symfony\AI\Platform\Message\Content\Document;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;

Expand All @@ -25,8 +25,7 @@
$messages = new MessageBag(
Message::ofUser(
'What is this document about?',
// Note: You can use either `File::fromFile` or `Document::fromFile` here.
File::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
Document::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
),
);
$result = $agent->call($messages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\Content\Document;
use Symfony\AI\Platform\Message\Content\File;
use Symfony\AI\Platform\Model;

Expand All @@ -39,7 +40,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =

protected function supportedDataClass(): string
{
return File::class;
return Document::class;
}

protected function supportsModel(Model $model): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\Contract\Normalizer\Message\MessageBagNormalizer;
use Symfony\AI\Platform\Message\Content\Document;
use Symfony\AI\Platform\Message\Content\File;

#[Medium]
#[CoversClass(DocumentNormalizer::class)]
Expand All @@ -34,9 +33,6 @@ public function testSupportsNormalization()
$this->assertTrue($normalizer->supportsNormalization(new Document('some content', 'application/pdf'), context: [
Contract::CONTEXT_MODEL => new Gpt(),
]));
$this->assertTrue($normalizer->supportsNormalization(new File('some content', 'application/pdf'), context: [
Contract::CONTEXT_MODEL => new Gpt(),
]));
$this->assertFalse($normalizer->supportsNormalization('not a document'));
}

Expand All @@ -45,26 +41,26 @@ public function testGetSupportedTypes()
$normalizer = new DocumentNormalizer();

$expected = [
File::class => true,
Document::class => true,
];

$this->assertSame($expected, $normalizer->getSupportedTypes(null));
}

#[DataProvider('normalizeDataProvider')]
public function testNormalize(File $file, array $expected)
public function testNormalize(Document $document, array $expected)
{
$normalizer = new DocumentNormalizer();

$normalized = $normalizer->normalize($file);
$normalized = $normalizer->normalize($document);

$this->assertEquals($expected, $normalized);
}

public static function normalizeDataProvider(): iterable
{
yield 'document from file' => [
File::fromFile(\dirname(__DIR__, 6).'/fixtures/document.pdf'),
Document::fromFile(\dirname(__DIR__, 6).'/fixtures/document.pdf'),
[
'type' => 'file',
'file' => [
Expand Down