Skip to content

fix(py): add singular ModelResponse.media accessor for first media part - #7139

Closed
huangjeff5 wants to merge 1 commit into
mainfrom
fix/py-1.0-pr3-media-accessor
Closed

huangjeff5 wants to merge 1 commit into
mainfrom
fix/py-1.0-pr3-media-accessor

Conversation

@huangjeff5

Copy link
Copy Markdown
Contributor

Adds a singular .media accessor to ModelResponse, Message, and ModelResponseChunk for parity with JS and Go.

Main Changes

  • Added response.media: Accessor returning Media | None pointing to the first media part.
  • Added response.media_parts: Accessor returning list[Media] for all media parts.
  • Preserved Document.media: Kept Document.media as a list to avoid breaking existing RAG contracts.

`ModelResponse.media` returned `list[Media]`, while JS `response.media`,
Go `Media()`, and Python's own `AgentResponse.media` return the first
media part. The `res.media.url` snippets in the google-genai README and
docstrings raised `AttributeError`, and `res.media[0]` raised
`IndexError` on empty replies.

- `ModelResponse.media -> Media | None` (first media part).
- New `ModelResponse.media_parts -> list[Media]` for the full list.
- `.media` on `Message` and `ModelResponseChunk`.
- `Document.media` stays a list.
- Update in-repo `.media[0]` users (bedrock README/docstrings/tests,
  operation docstrings, veo tests, samples) and add a migration line.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors how media parts are accessed in ModelResponse, Message, and ModelResponseChunk. Specifically, the media property has been changed from returning a list of media parts to returning only the first media part (Media | None), aligning the Python SDK with the JS and Go implementations. A new media_parts property has been introduced to retrieve the full list of media parts. Documentation, tests, samples, and plugin packages (Amazon Bedrock, Google GenAI, Vertex AI) have been updated accordingly to use the new properties. There are no review comments, so I have no feedback to provide.

@huangjeff5

Copy link
Copy Markdown
Contributor Author

Closing: migrated to standalone repository genkit-ai/genkit-python (PR #47): genkit-ai/genkit-python#47

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant