Skip to content

Conversation

glengemann
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Docs? no
Issues Fix #...
License MIT

Hi there!

Currently, if you try to add a file into the message input, the following error is thrown:

// PHP Fatal error:  Uncaught Symfony\Component\Serializer\Exception\NotNormalizableValueException: Could not normalize object of type "Symfony\AI\Platform\Message\Content\File", no supporting normalizer found.

Message::ofUser(
    'What is this document about?',
    File::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
)

This PR adds support for including files as inputs in the OpenAI completions API, as described in the official documentation. The implementation follows the same approach already used for Gemini and Anthropic.

@carsonbot carsonbot changed the title OpenAI: Add File Input Normalizer OpenAI: Add File Input Normalizer Aug 27, 2025
@OskarStark OskarStark added Platform Issues & PRs about the AI Platform component Run examples Issues & PRs about the example scripts labels Aug 29, 2025
@carsonbot carsonbot changed the title OpenAI: Add File Input Normalizer [Examples][Platform] OpenAI: Add File Input Normalizer Aug 29, 2025
@OskarStark OskarStark removed the Run examples Issues & PRs about the example scripts label Aug 29, 2025
@carsonbot carsonbot changed the title [Examples][Platform] OpenAI: Add File Input Normalizer [Platform] OpenAI: Add File Input Normalizer Aug 29, 2025
@OskarStark OskarStark changed the title [Platform] OpenAI: Add File Input Normalizer [Platform][OpenAI] Add File Input Normalizer Aug 29, 2025
@OskarStark OskarStark changed the title [Platform][OpenAI] Add File Input Normalizer [Platform][OpenAI] Add file input normalizer Aug 29, 2025
@chr-hertel
Copy link
Member

One thing that got me thinking is that we use the OpenAI contract mostly as default - meaning that the normalizers are mostly in namespace Symfony\AI\Platform\Contract\Normalizer - but I tested with Ollama and Cerebras, that are basically using that contract, but got errors - so i guess it's fine to only have it for OpenAI instead of default.

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, would love to merge that - one tiny thing noted about the normalizer name.

@chr-hertel
Copy link
Member

Thank you @glengemann.

@chr-hertel chr-hertel merged commit e7bec23 into symfony:main Aug 29, 2025
7 checks passed
chr-hertel added a commit that referenced this pull request Aug 31, 2025
This PR was merged into the main branch.

Discussion
----------

[Platform] Fix doc type on FileNormalizer

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| Docs?         | no
| Issues        |
| License       | MIT

Follows #357

Commits
-------

8a6f763 Fix doc type on FileNormalizer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature Platform Issues & PRs about the AI Platform component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants