Skip to content

feat(py): Anthropic.claude_model and OpenAI.gpt_model typed ref constructors - #6105

Merged
huangjeff5 merged 7 commits into
feat/py-typed-family-refs-google-vertexfrom
feat/py-typed-family-refs-anthropic-openai
Aug 20, 2026
Merged

huangjeff5 merged 7 commits into
feat/py-typed-family-refs-google-vertexfrom
feat/py-typed-family-refs-anthropic-openai

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Anthropic.claude_model namespaces the id and binds AnthropicConfig. Unknown ids are allowed; every Anthropic generate model takes that schema.
  • OpenAI.gpt_model is chat-only. Image, TTS, STT, and embedding ids validate different request shapes, so binding OpenAIConfig would let chat-only keys like frequency_penalty ride into the wrong endpoint. Those ids raise INVALID_ARGUMENT and keep working as plain strings (openai_model(...)).
  • Foreign prefixes (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.
  • Chat actions opt into ModelRequest[OpenAIConfig] / ModelRequest[AnthropicConfig], so the string generate path validates plugin config today (temperature: 3 is INVALID_ARGUMENT). OpenAIConfig accepts camelCase aliases so Dev UI / reflection knobs (frequencyPenalty, maxOutputTokens) land. maxOutputTokens is accepted; it is not mapped to max_tokens.
  • Unlisted chat ids that ask for JSON (no schema) get json_object. The provider rejects the request if that model cannot do JSON mode.
  • KnownClaude / KnownGpt are catalog Literals so quote autocomplete and the supported-model dict are the same set.
  • openai_model() stays the string name helper.
  • refs can be minted but all the end-user surfaces (generate, agent, prompt, Genkit() constructor) still want a string, until feat(py): accept ModelRef on generate, prompt, agent, and Genkit constructor #6074 lands.

@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 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.

@github-actions github-actions Bot added the python Python label Aug 18, 2026
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-anthropic-openai branch from 2cf83eb to 4afb92b Compare August 18, 2026 22:22
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-anthropic-openai branch from 4afb92b to e432951 Compare August 19, 2026 17:06
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-anthropic-openai branch from 84b2cbf to ddc780c Compare August 19, 2026 21:52
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-anthropic-openai branch 2 times, most recently from 149a3c6 to 2fc4672 Compare August 19, 2026 22:18
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-anthropic-openai branch from 2fc4672 to 51b6a38 Compare August 19, 2026 22:23
…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.
@huangjeff5
huangjeff5 force-pushed the feat/py-typed-family-refs-anthropic-openai branch from 51b6a38 to 0ff2901 Compare August 20, 2026 19:11
@huangjeff5

Copy link
Copy Markdown
Contributor Author

@gemini review

@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 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.

@huangjeff5
huangjeff5 merged commit 6b68afb into main Aug 20, 2026
24 checks passed
@huangjeff5
huangjeff5 deleted the feat/py-typed-family-refs-anthropic-openai 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