Skip to content

feat(py): typed family ref constructors on GoogleAI and VertexAI - #6104

Merged
huangjeff5 merged 3 commits into
fix/py-type-google-family-actionsfrom
feat/py-typed-family-refs-google-vertex
Aug 20, 2026
Merged

huangjeff5 merged 3 commits into
fix/py-type-google-family-actionsfrom
feat/py-typed-family-refs-google-vertex

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • One classmethod per config family (gemini_model, gemini_tts_model, gemini_image_model, gemma_model, imagen_model, embedding) so the method name is what picks ModelRef[T] / EmbedderRef.
  • Constructors strip prefixes (model/, models/, googleai/, vertexai/, …) and stamp this plugin's namespace. A pasted cross-plugin name cannot smuggle its namespace into the ref. The specific prefixes to strip are defined within each plugin.
  • Ids whose runtime action validates a different schema are refused with a hint at the right constructor. Unknown ids stay usable through gemini_model / embedding so a new release works before this plugin learns its name.
  • GoogleAI.embedding() / VertexAI.embedding() return an EmbedderRef. That is usable today: ai.embed(embedder=GoogleAI.embedding('gemini-embedding-001'), content=…). Named embedding so Plugin.embedder still resolves an Action.
  • gemini_model() and the other generate constructors are typed factories. ai.generate(model=…) is still str until feat(py): accept ModelRef on generate, prompt, agent, and Genkit constructor #6074. Samples stay on string model=.

Test plan

  • GoogleAI.gemini_model('gemini-2.5-flash').name == 'googleai/gemini-2.5-flash' and the Vertex twin stamps vertexai/
  • Pasted vertexai/…, models/…, models/googleai/… all land on the constructor's namespace
  • gemini_model refuses Veo / Lyria / Interactions / embedder / TTS / image / Gemma / Imagen / retired image ids
  • GoogleAI.embedding('gemini-embedding-001') is an EmbedderRef, not a ModelRef
  • await plugin.embedder('gemini-embedding-001') is still an Action
  • KnownGemini / TTS / image / Gemma / Imagen Literals match the import-time catalog (not ids resolve() writes later)

@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 introduces typed family reference constructors (such as gemini_model, gemma_model, and imagen_model) shared by the GoogleAI and VertexAI plugins, along with string literal types to support autocomplete. The feedback recommends ensuring backward compatibility with Python 3.9 by removing the TypeAlias imports and annotations, and suggests adding defensive type checking in _model_refs.py to prevent non-string inputs from being silently converted and accepted.

@github-actions github-actions Bot added the python Python label Aug 18, 2026
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-google-vertex branch from a3b7ded to 7b3fc70 Compare August 18, 2026 22:22
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-google-vertex branch from 7b3fc70 to 896eb16 Compare August 19, 2026 16:54
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-google-vertex branch from c07cc84 to e4ea4f0 Compare August 19, 2026 21:52
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-google-vertex branch from e4ea4f0 to c148b4e Compare August 19, 2026 22:01
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-google-vertex branch from d651eab to eaab4ff Compare August 19, 2026 22:23
One classmethod per config family (gemini_model, gemini_tts_model,
gemini_image_model, gemma_model, imagen_model, embedding) because the
method name is what picks the return type; Python cannot infer it from
an open string. Constructors strip pasted prefixes (model/, models/,
googleai/, vertexai/, ...) and stamp their own namespace, so a pasted
cross-plugin name cannot smuggle its namespace into the ref. Ids whose
action validates a different schema are refused with a hint at the right
constructor; unknown ids stay usable through gemini_model so new releases
work before the plugin learns their names. embedding() returns an
EmbedderRef, never a ModelRef, and keeps Plugin.embedder as the Action
resolve helper.
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-google-vertex branch from eaab4ff to e39aacc Compare August 20, 2026 19:11
@huangjeff5
huangjeff5 merged commit 847af60 into main Aug 20, 2026
24 checks passed
@huangjeff5
huangjeff5 deleted the feat/py-typed-family-refs-google-vertex branch August 20, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants