-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Improve the way of selecting file extensions and support automatic selection of file extensions #3789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request improves the file extension and media type selection mechanism for FileUrl and BinaryContent classes. The key changes enable automatic media type detection using Magika (preferred) or python-magic (fallback) when media type is not explicitly provided.
Key Changes:
- Implements automatic media type detection for
BinaryContentusing Magika or python-magic libraries - Refactors
FileUrlsubclasses to use a common_infer_media_typebase implementation with fallback tomimetypes.guess_type - Adds internal caching fields (
_media_type,_type,_extension) to optimize repeated access - Updates error messages to be more generic (e.g., "Could not infer media type from URL" instead of media-specific messages)
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
pydantic_ai_slim/pydantic_ai/messages.py |
Core implementation of automatic media type detection, adds computed property for media_type, refactors FileUrl format inference, and adds caching fields |
pydantic_ai_slim/pyproject.toml |
Adds python-magic>=0.4.27 as required dependency and magika>=1.0.1 as optional dependency |
tests/test_messages.py |
Updates test snapshots to include _media_type parameter and removes obsolete test for DocumentUrl format error |
tests/test_vercel_ai.py |
Updates test snapshots to include _media_type parameter in BinaryImage and BinaryContent instances |
tests/test_mcp.py |
Updates test snapshots to include _media_type parameter |
tests/test_fastmcp.py |
Updates test snapshots to include _media_type parameter |
tests/test_agent_output_schemas.py |
Updates JSON schema snapshots to reflect new computed field behavior and reordered required fields |
tests/test_agent.py |
Updates test snapshots to include _media_type parameter |
tests/models/test_openai_responses.py |
Updates test snapshots across multiple test cases to include _media_type parameter |
tests/models/test_mistral.py |
Updates test snapshots to include _media_type parameter |
tests/models/test_google.py |
Updates test snapshots to include _media_type parameter |
tests/evals/test_reporting.py |
Updates table formatting snapshots (unrelated formatting changes) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Improve the way of selecting file extension or mediatype and support automatic selection of file mediatype for FileUrl or BinaryContent
Fix #3349