Skip to content

Gemini Video Support #1584

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 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ You can provide audio input using either [`AudioUrl`][pydantic_ai.AudioUrl] or [
## Video Input

!!! info
Some models do not support video input. Please check the model's documentation to confirm whether it supports audio input.
Some models do not support video input. Please check the model's documentation to confirm whether it supports video input.

You can provide video input using either [`VideoUrl`][pydantic_ai.VideoUrl] or [`BinaryContent`][pydantic_ai.BinaryContent]. The process is analogous to the examples above.

Expand Down
4 changes: 1 addition & 3 deletions pydantic_ai_slim/pydantic_ai/models/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ async def _map_user_prompt(self, part: UserPromptPart) -> list[_GeminiPartUnion]
content.append(
_GeminiInlineDataPart(inline_data={'data': base64_encoded, 'mime_type': item.media_type})
)
elif isinstance(item, (AudioUrl, ImageUrl, DocumentUrl)):
elif isinstance(item, (AudioUrl, ImageUrl, DocumentUrl, VideoUrl)):
client = cached_async_http_client()
response = await client.get(item.url, follow_redirects=True)
response.raise_for_status()
Expand All @@ -337,8 +337,6 @@ async def _map_user_prompt(self, part: UserPromptPart) -> list[_GeminiPartUnion]
inline_data={'data': base64.b64encode(response.content).decode('utf-8'), 'mime_type': mime_type}
)
content.append(inline_data)
elif isinstance(item, VideoUrl): # pragma: no cover
raise NotImplementedError('VideoUrl is not supported for Gemini.')
else:
assert_never(item)
return content
Expand Down

Large diffs are not rendered by default.

Loading