diff --git a/examples/openai/pdf-input-binary.php b/examples/openai/pdf-input-binary.php index 1f9cefc5f..674e7f2be 100644 --- a/examples/openai/pdf-input-binary.php +++ b/examples/openai/pdf-input-binary.php @@ -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; @@ -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); diff --git a/src/platform/src/Bridge/OpenAi/Contract/DocumentNormalizer.php b/src/platform/src/Bridge/OpenAi/Contract/DocumentNormalizer.php index 594eafadd..b081e30b1 100644 --- a/src/platform/src/Bridge/OpenAi/Contract/DocumentNormalizer.php +++ b/src/platform/src/Bridge/OpenAi/Contract/DocumentNormalizer.php @@ -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; @@ -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 diff --git a/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php b/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php index 165961538..4c9317b0f 100644 --- a/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php +++ b/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php @@ -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)] @@ -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')); } @@ -45,18 +41,18 @@ 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); } @@ -64,7 +60,7 @@ public function testNormalize(File $file, array $expected) 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' => [