feat(chat): forgiving string coercion for vendor_type/api_flavor in get_chat_model - #1011
Closed
denispetre wants to merge 1 commit into
Closed
feat(chat): forgiving string coercion for vendor_type/api_flavor in get_chat_model#1011denispetre wants to merge 1 commit into
denispetre wants to merge 1 commit into
Conversation
…ing_mode get_chat_model already documents these params as accepting strings, but the underlying enum coercion is strict exact-value matching — 'AWSBedrock', 'CONVERSE', and 'anthropic_messages' were rejected while 'awsbedrock', 'converse', and 'AnthropicMessages' worked. The wrapper now resolves string inputs case-insensitively against both member names and values, with hyphens and underscores interchangeable, and raises a ValueError listing the valid values when nothing matches (before any factory call). Enum members and None pass through unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Contributor
Author
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.



What
get_chat_modeldocumentsvendor_type: VendorType | str | None,api_flavor: ApiFlavor | str | None, androuting_mode: RoutingMode | str— but string handling downstream is strict exact-value enum matching:"awsbedrock""AWSBedrock"VendorType.AWSBEDROCK"CONVERSE"ApiFlavor.CONVERSE"anthropic_messages"AnthropicMessages)ApiFlavor.ANTHROPIC_MESSAGES"not-a-flavor"ValueErrorlisting the valid values, raised before any factory callThe wrapper now resolves string inputs case-insensitively against both member names and values, treating
-/_as interchangeable. Enum members andNonepass through unchanged — fully backward compatible (only previously-failing inputs change behavior).Why
Callers supplying the API flavor as a string (config files, CI workflow inputs — e.g. the model-onboarding testcase's
vendor:flavorpath syntax in #1009) shouldn't need to know that Bedrock's Anthropic flavor is spelledAnthropicMessageswhile everything else is kebab-case.Tests
tests/chat/test_chat_model_factory_coercion.py— 23 tests: spelling variants per enum, pass-through of members/None, forwarding into the client factory (patched), and the earlyValueErrorwith valid values listed. Ruff clean; pre-existing collection errors intests/chat/(missing optionalbedrockextras in a non---all-extrasvenv) are unrelated and unchanged.🤖 Generated with Claude Code