Repository navigation
feat(py): normalize model+config for str | ModelRef - #6015
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces model resolution helper functions (normalize_config, resolve_model_name, and resolve_model_ref) along with their corresponding unit tests. The review feedback suggests enhancing type safety and robustness by explicitly checking for supported types in normalize_config, validating that the resolved model name is a string in resolve_model_name, and adding corresponding unit tests for these edge cases.
d88730a to
c3f4097
Compare
|
@gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces model resolution and configuration normalization helpers in the Genkit Python SDK, including the normalize_config, resolve_model_name, and resolve_model_ref functions, along with a ResolvedModel dataclass to handle merging and normalizing model configurations. It also adds a comprehensive suite of unit tests to verify these behaviors. There are no review comments, so I have no feedback to provide.
5006e6b to
b340f97
Compare
8907f22 to
c73fdc3
Compare
d8cbd8f to
c7aa20e
Compare
Extracted from #5977: ResolvedModel, normalize_config, resolve_model_name, resolve_model_ref + ModelArg/ConfigArg aliases. No call sites change. Merge precedence (low to high): ref.version, ref.config, call-time config; explicit None clears lower layers.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
… and ormalize_config still keeps None so it can overlay a ref default
2bb58bd to
c8feb38
Compare
Product (this is the layer for #6074)
generate/define_prompt/ agents /Genkit(model=)will take onemodel=that is a name or aModelRef:flashcarries a wire name plus defaults (version,config). A string is just the name. Same slot, two shapes. That union — including the constructor — is #6074.To implement it, every path has to become one wire name + one config bag before the plugin runs. This PR is that normalization layer.
What the layer has to survive
E2e of these lives on #6074. They are listed here because they are what the helpers are for.
With a bare string
model=there is no schema, so nothing folds — dict keys pass through as written.Principles (this PR)
The pipeline is four steps, each doing one thing:
normalize_config): a config object or dict becomes a plain dict. Pydantic dumps the Python field names; dict keys stay as written; no fold, no merge.api_key(exclude=True) is copied back so a per-request key still reaches the plugin.fold_config_aliases): schema aliases rename to the field name (maxOutputTokens→max_output_tokens). A rename, not validation — unknown keys keep their spelling.overlay_config): fold each layer, last layer wins, dropNone. Both spellings of one knob land in one slot, so a camel override or clear cannot leave a stale snake sibling.resolve_model_ref/resolve_call_model): stackref.version→ dumpedref.config→ callconfig=, overlay once. Merge is shallow, by key. OnlyNonemeans omit; empty values are explicit. The helper does not know families.The merged result is a dict.
ModelRequestrebuilds genericModelConfigtoday; plugin-typed parse is #5986.Genkit(model=)stays a string here. Dev UI/api/valuesunwraps a storedModelRefto the wire name so listing does not 500; that path is ready for #6074.What lands here vs later
normalize_config/fold_config_aliases/overlay_config/resolve_model_arg/resolve_model_ref/resolve_call_model. Constructor remainsstr.Genkit(model=),generate(model=),define_prompt, agents, stream,generate_operation.ModelRequest[GeminiConfig]— plugin-only fields as real attributes.