Repository navigation
fix(py)!: one declaration per common config field; non-text configs extend GenkitConfig - #6978
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors model configuration across multiple plugins (including Amazon Bedrock, Anthropic, Google GenAI, Ollama, and OpenAI) by consolidating common fields into a unified ModelConfig base class in genkit core. Subclasses now use a common_field_bounds dictionary to specify provider-specific ranges rather than re-declaring fields, and native provider-specific names are rejected in favor of the common fields. Feedback on the changes suggests using .get() when retrieving fields from cls.model_fields to prevent potential KeyError exceptions if common_field_bounds is misconfigured.
This was referenced Nov 2, 2026
huangjeff5
force-pushed
the
fix/py-common-config-fields
branch
3 times, most recently
from
November 2, 2026 12:23
760f5b7 to
30e3244
Compare
huangjeff5
force-pushed
the
fix/py-common-config-fields
branch
from
November 2, 2026 16:58
30e3244 to
84707c6
Compare
pavelgj
approved these changes
Nov 2, 2026
huangjeff5
force-pushed
the
fix/py-common-config-fields
branch
from
November 2, 2026 23:03
84707c6 to
96a7e2c
Compare
…xtend GenkitConfig ModelConfig declares the common fields itself (int token counts) instead of inheriting the generated GenerationCommonConfig. Plugins no longer re-declare or alias them: Gemini/OpenAI ranges move to common_field_bounds, Ollama drops num_predict/stop, OpenAI drops max_tokens/max_completion_tokens/stop (top-level use fails as an unknown config key; extra passes raw wire fields through). OpenAI image, TTS and STT configs extend GenkitConfig. A repo-level guard test enforces the rule.
huangjeff5
force-pushed
the
fix/py-common-config-fields
branch
from
November 2, 2026 23:46
96a7e2c to
2769d65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each common config setting has one Python name, declared once on
ModelConfig(temperature,max_output_tokens,top_k,top_p,stop_sequences,version). Plugins map the common field to their wire spelling instead of re-declaring it or adding a provider-specific alias; raw wire fields still pass straight throughextra.On main that didn't hold:
OpenAIConfighadmax_tokens,max_completion_tokensandstopnext tomax_output_tokensandstop_sequences, plus a rule for which one wins. fix(py/ollama)!: per-request key comes from context.secrets; OllamaConfig declares all sampler options #6643 copied the pattern intoOllamaConfig(num_predict,stop).GeminiConfigre-declared five common fields to tighten bounds, behind pyright/pyrefly ignores.ModelConfiginherited the generatedGenerationCommonConfig, which types token counts asfloat.ModelConfig, sotemperatureondall-e-3was accepted and silently dropped.Main Changes
ModelConfignow extendsGenkitConfigand declares the six fields itself, withmax_output_tokens: intandtop_k: int, matching Go.GenerationCommonConfigstays as the schema's record. A test pinsModelConfig's names and wire aliases to it.256.0validates,2.5does not.int(...)casts in Anthropic, Bedrock and OpenAI are gone.common_field_bounds = {'temperature': (0.0, 2.0)}. This is new public API for plugin authors.ModelConfigchecks it in a field validator, so a violation is the usualINVALID_ARGUMENTon that field, with error typecommon_field_bounds. It also writesminimum/maximuminto the Dev UI schema.top_p.extrastays a raw passthrough.num_predict/stopon Ollama andmax_tokens/max_completion_tokens/stopon OpenAI are omitted from the config schema, so top-level use fails viaGenkitConfig'sextra='forbid'without per-plugin special cases.extrapasses raw wire fields through untouched (matching Anthropic), giving OpenAI-compatible servers an explicit override when model-name heuristics pick the wrong token-cap field.GenkitConfig.OpenAIDalleConfig,OpenAIGptImageConfig,OpenAITtsConfigandOpenAISttConfigdeclare only what their endpoint reads, likeVeoConfig.temperature, so0is now sent, andtranslate, which the model already read but the schema rejected.version; name the model directly.GeminiTtsConfig/GeminiImageConfigstay onGeminiConfig, becausegenerateContenttakes the sampling knobs.py/tests/config_field_guard_test.pywalks every config class in the Bedrock, Anthropic, Google GenAI, Ollama, OpenAI and Vertex AI plugins. It fails when a plugin class re-annotates a common field or declares a known native alias. It reads annotations withinspect.get_annotations, so it still checks on 3.14 (PEP 649), and positive-control tests prove it flags a re-declared field.Breaking
ModelConfigno longer subclassesGenerationCommonConfig.max_output_tokensandtop_kareint | None, and a fractional value raises.OllamaConfig:num_predictandstopremoved from top-level config. Usemax_output_tokensandstop_sequences(rawoptionspassthrough viaextrastill works).OpenAIConfig:max_tokens,max_completion_tokensandstopremoved from top-level config.max_output_tokensandstop_sequences, or pass raw body fields inextra(e.g., to forcemax_tokensvsmax_completion_tokenson an OpenAI-compatible server).max_output_tokensis sent asmax_completion_tokenson reasoning models or withreasoning_effort, else asmax_tokens.stopat the top level is gone.GenkitConfig. Text knobs (excepttemperatureon STT) andversionraise instead of being dropped.common_field_boundsandtemperature must be between …, not pydantic'sless_than_equal/greater_than_equal.temperature/top_pare now range-checked locally instead of being sent to the API.Invalid value, like any custom validator error, not pydantic's built-in range text.temperature/top_pschema is now nullable (anyOf: [number, null]), withminimum/maximumbeside it.