Repository navigation
feat(py): Anthropic.claude_model and OpenAI.gpt_model typed ref constructors - #6105
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces typed model reference constructors (claude_model for Anthropic and gpt_model for OpenAI) that return ModelRef instances bound to their respective configuration schemas (AnthropicConfig and OpenAIConfig). It also defines KnownClaude and KnownGpt literal types to enable autocomplete and static type checking for supported model IDs. A high-severity issue was identified in the OpenAI model handler where direct dictionary indexing of SUPPORTED_OPENAI_MODELS with a casted model name could raise a KeyError at runtime for unlisted or custom models; using .get() with a fallback is recommended to prevent crashes.
2cf83eb to
4afb92b
Compare
4afb92b to
e432951
Compare
84b2cbf to
ddc780c
Compare
149a3c6 to
2fc4672
Compare
2fc4672 to
51b6a38
Compare
…ructors Classmethods matching the Google plugin shape. claude_model allows unknown ids (every Anthropic generate model takes AnthropicConfig). gpt_model is chat-only: image/TTS/STT/embedding ids validate different request shapes, so binding OpenAIConfig to them would let chat-only keys like frequency_penalty ride into the wrong endpoint; those ids raise INVALID_ARGUMENT and keep working as plain strings. KnownGpt is the chat catalog Literal so quote autocomplete stays locked to that set. openai_model() stays the string name helper. Chat plugin actions opt into ModelRequest[Config] so Action validates the plugin schema.
51b6a38 to
0ff2901
Compare
|
@gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces typed model reference constructors (claude_model for Anthropic and gpt_model for OpenAI) that return ModelRef instances bound to their respective configuration schemas (AnthropicConfig and OpenAIConfig). It defines KnownClaude and KnownGpt literals to provide autocomplete and type safety for supported model IDs, while still allowing unknown IDs. Additionally, it refactors configuration handling to properly strip Genkit-specific keys before sending requests to the APIs, adds camelCase alias support for OpenAIConfig to integrate with the Dev UI, and introduces comprehensive unit tests for these new features. There are no review comments, so I have no feedback to provide.
Summary
Anthropic.claude_modelnamespaces the id and bindsAnthropicConfig. Unknown ids are allowed; every Anthropic generate model takes that schema.OpenAI.gpt_modelis chat-only. Image, TTS, STT, and embedding ids validate different request shapes, so bindingOpenAIConfigwould let chat-only keys likefrequency_penaltyride into the wrong endpoint. Those ids raiseINVALID_ARGUMENTand keep working as plain strings (openai_model(...)).vertexai/…,azure/…) stay in the name. This constructor does not remap a Vertex or Azure paste onto Anthropic/OpenAI — that would hit the wrong API.ModelRequest[OpenAIConfig]/ModelRequest[AnthropicConfig], so the string generate path validates plugin config today (temperature: 3isINVALID_ARGUMENT).OpenAIConfigaccepts camelCase aliases so Dev UI / reflection knobs (frequencyPenalty,maxOutputTokens) land.maxOutputTokensis accepted; it is not mapped tomax_tokens.json_object. The provider rejects the request if that model cannot do JSON mode.KnownClaude/KnownGptare catalog Literals so quote autocomplete and the supported-model dict are the same set.openai_model()stays the string name helper.