Repository navigation
feat(py): support ModelRef in ai.generate() and ai.define_prompt() - #5966
huangjeff5 wants to merge 33 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for typed and frozen ModelRef objects across the generation and prompt APIs, allowing model references to carry default configurations that are validated and merged with call-time overrides. Feedback on the changes suggests removing redundant unit tests for ModelRef from model_test.py since the same behavior is already covered in the newly created model_ref_test.py file.
I am having trouble creating individual review comments. Click here to see my feedback.
py/packages/genkit/tests/genkit/ai/model_test.py (381-416)
These tests for ModelRef seem redundant, as similar, more specific tests are added in the new py/packages/genkit/tests/genkit/ai/model_ref_test.py file. To avoid test duplication and keep tests organized, it would be better to have all ModelRef unit tests in model_ref_test.py.
Consider removing test_model_ref_generic_construction and test_model_ref_immutability from this file. The functionality is already covered by test_model_ref_stamps_namespace_and_schema, test_model_ref_stamps_typed_config, and test_model_ref_is_frozen in model_ref_test.py.
…(handled by Mapping[str, Any])
…prompt overload matching
…nerate and generate_stream
…oad serialization
… model_ref_test.py
Summary
Enables passing typed
ModelRefinstances directly toai.generate(),ai.generate_stream(),ai.generate_operation(), andai.define_prompt().Key Changes
resolve_model_arg()helper: Automatically extracts the wire model name (model.name), default configuration (model.config), and version from aModelRef. Merges call-time configuration overrides on top of theModelRef's default configuration and validates against its concrete Pydantic schema.Genkit.generate(),Genkit.generate_stream(),Genkit.generate_operation(), andGenkit.define_prompt()signatures to acceptmodel: str | ModelRef[BaseModel] | None.model_ref_generate_test.pyandmodel_ref_test.pycovering end-to-end generation withModelRefand config override merging behavior.Builds on #5965.