Repository navigation
refactor(py/plugins/google-genai): trim dead Lyria helpers - #6783
Conversation
2446fb9 to
54a226e
Compare
There was a problem hiding this comment.
Code Review
This pull request adds support for the Vertex AI Virtual Try-On model (virtual-try-on-001) to the genkit-google-genai package, including configuration schemas, routing, and comprehensive tests. The review feedback suggests several important safety improvements to prevent runtime exceptions, such as using the internal StrEnum compatibility layer to avoid dependency issues on Python < 3.11, ensuring media URLs are not empty before processing, and guarding against a None context when retrieving client configurations.
I am having trouble creating individual review comments. Click here to see my feedback.
py/packages/genkit-google-genai/src/genkit_google_genai/models/virtual_try_on.py (35-42)
Using strenum directly can cause a ModuleNotFoundError on Python < 3.11 if the package is not installed. Since genkit already provides a compatible StrEnum implementation in genkit._core._compat, it is safer and more consistent to use that instead.
from collections.abc import Mapping
from typing import Any, Literal, TypeAlias
from genkit._core._compat import StrEnum
py/packages/genkit-google-genai/src/genkit_google_genai/models/virtual_try_on.py (232-237)
If part.media.url is None or empty, appending it to urls can cause runtime errors (such as AttributeError when calling startswith on None) in _to_image. It is safer to check that part.media.url is present and non-empty before appending it.
for part in request.messages[-1].content:
if part.media is None or not part.media.url:
continue
metadata = part.metadata
if isinstance(metadata, dict) and metadata.get('type') == part_type:
urls.append(part.media.url)
py/packages/genkit-google-genai/src/genkit_google_genai/models/virtual_try_on.py (383-386)
If ctx.context is None, calling context.get('config') will raise an AttributeError. Guarding against None by defaulting context to an empty dictionary ensures safety.
context = ctx.context or {}
api_key = context_api_key(context)
context_config = context.get('config')
context_config = context_config if isinstance(context_config, dict) else {}
Fixes #6185
Summary
The issue's speech config items landed with #6328 and #6593, and the
ImagenConfigSchemaitem with #6305, which retired Imagen. This closes the Lyria item._models/_lyria.pystill carried aLyriaConfig, aKNOWN_LYRIA_MODELSset, model info, and request/response helpers for the predict API. Nothing imports them, and the package'sLyriaConfigexport comes from_interactions_lyria. The module now keeps onlyis_lyria_model, which routing uses.