Skip to content

Commit 31a4b03

Browse files
committed
bug #496 [Platform] Fix Image vs Document support in OpenAI contract (chr-hertel)
This PR was merged into the main branch. Discussion ---------- [Platform] Fix Image vs Document support in OpenAI contract | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Docs? | no | Issues | | License | MIT another fix :D Commits ------- 561a88f Fix Image vs Document support in OpenAI contract
2 parents 4169efe + 561a88f commit 31a4b03

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

examples/openai/pdf-input-binary.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\AI\Agent\Agent;
1313
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
1414
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
15-
use Symfony\AI\Platform\Message\Content\File;
15+
use Symfony\AI\Platform\Message\Content\Document;
1616
use Symfony\AI\Platform\Message\Message;
1717
use Symfony\AI\Platform\Message\MessageBag;
1818

@@ -25,8 +25,7 @@
2525
$messages = new MessageBag(
2626
Message::ofUser(
2727
'What is this document about?',
28-
// Note: You can use either `File::fromFile` or `Document::fromFile` here.
29-
File::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
28+
Document::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
3029
),
3130
);
3231
$result = $agent->call($messages);

src/platform/src/Bridge/OpenAi/Contract/DocumentNormalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
1515
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
16+
use Symfony\AI\Platform\Message\Content\Document;
1617
use Symfony\AI\Platform\Message\Content\File;
1718
use Symfony\AI\Platform\Model;
1819

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

4041
protected function supportedDataClass(): string
4142
{
42-
return File::class;
43+
return Document::class;
4344
}
4445

4546
protected function supportsModel(Model $model): bool

src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\AI\Platform\Contract;
2121
use Symfony\AI\Platform\Contract\Normalizer\Message\MessageBagNormalizer;
2222
use Symfony\AI\Platform\Message\Content\Document;
23-
use Symfony\AI\Platform\Message\Content\File;
2423

2524
#[Medium]
2625
#[CoversClass(DocumentNormalizer::class)]
@@ -34,9 +33,6 @@ public function testSupportsNormalization()
3433
$this->assertTrue($normalizer->supportsNormalization(new Document('some content', 'application/pdf'), context: [
3534
Contract::CONTEXT_MODEL => new Gpt(),
3635
]));
37-
$this->assertTrue($normalizer->supportsNormalization(new File('some content', 'application/pdf'), context: [
38-
Contract::CONTEXT_MODEL => new Gpt(),
39-
]));
4036
$this->assertFalse($normalizer->supportsNormalization('not a document'));
4137
}
4238

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

4743
$expected = [
48-
File::class => true,
44+
Document::class => true,
4945
];
5046

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

5450
#[DataProvider('normalizeDataProvider')]
55-
public function testNormalize(File $file, array $expected)
51+
public function testNormalize(Document $document, array $expected)
5652
{
5753
$normalizer = new DocumentNormalizer();
5854

59-
$normalized = $normalizer->normalize($file);
55+
$normalized = $normalizer->normalize($document);
6056

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

6460
public static function normalizeDataProvider(): iterable
6561
{
6662
yield 'document from file' => [
67-
File::fromFile(\dirname(__DIR__, 6).'/fixtures/document.pdf'),
63+
Document::fromFile(\dirname(__DIR__, 6).'/fixtures/document.pdf'),
6864
[
6965
'type' => 'file',
7066
'file' => [

0 commit comments

Comments
 (0)