Skip to content

Support google file api urls #2270

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dprov
Copy link

@dprov dprov commented Jul 22, 2025

@@ -92,6 +92,9 @@ class FileUrl(ABC):
url: str
"""The URL of the file."""

_media_type: str | None = field(default=None, repr=False)
Copy link
Author

Choose a reason for hiding this comment

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

@DouweM I diverged from your proposition of setting media_type in the __post_init__, because I realized (after the fact...) that it would make it mandatory to specify it in cases where it's not needed/relevant, e.g. when force_download==True or when it's a youtube video url. (I figured making the field optional would be too messy)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, defining it as a private field (with the underscore) makes sense, but since we want users to set this, the keyword argument on the constructor should not have an underscore. So I think we'll need a custom __init__ method (and overrides on the subclasses)

Copy link
Author

Choose a reason for hiding this comment

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

I did it using an InitVar + __post_init__ to avoid having to define the whole init for FileUrl + subclasses. Is that ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

I commented below but the argument really should be media_type without the confusing final underscore. Since this is a library, the cleanness of the public interface is more important than the cleanness of the code to make it work. :)

@@ -92,6 +92,9 @@ class FileUrl(ABC):
url: str
"""The URL of the file."""

_media_type: str | None = field(default=None, repr=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, defining it as a private field (with the underscore) makes sense, but since we want users to set this, the keyword argument on the constructor should not have an underscore. So I think we'll need a custom __init__ method (and overrides on the subclasses)

@dprov dprov requested a review from DouweM July 23, 2025 12:32
document_url = DocumentUrl(url='https://example.com/document.pdf')
assert document_url.media_type == 'application/pdf'
assert document_url.format == 'pdf'

document_url = DocumentUrl(url='https://example.com/document', media_type_='application/pdf')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we make the argument media_type? That may require a custom __init__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support passing files uploaded to Gemini Files API
2 participants