Skip to content

feat(chat): forgiving string coercion for vendor_type/api_flavor in get_chat_model - #1011

Closed
denispetre wants to merge 1 commit into
mainfrom
feat/chat-flavor-string-coercion
Closed

feat(chat): forgiving string coercion for vendor_type/api_flavor in get_chat_model#1011
denispetre wants to merge 1 commit into
mainfrom
feat/chat-flavor-string-coercion

Conversation

@denispetre

Copy link
Copy Markdown
Contributor

What

get_chat_model documents vendor_type: VendorType | str | None, api_flavor: ApiFlavor | str | None, and routing_mode: RoutingMode | str — but string handling downstream is strict exact-value enum matching:

input before after
"awsbedrock"
"AWSBedrock" ❌ rejected VendorType.AWSBEDROCK
"CONVERSE" ❌ rejected ApiFlavor.CONVERSE
"anthropic_messages" ❌ rejected (must spell AnthropicMessages) ApiFlavor.ANTHROPIC_MESSAGES
"not-a-flavor" opaque downstream failure ValueError listing the valid values, raised before any factory call

The wrapper now resolves string inputs case-insensitively against both member names and values, treating -/_ as interchangeable. Enum members and None pass 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:flavor path syntax in #1009) shouldn't need to know that Bedrock's Anthropic flavor is spelled AnthropicMessages while 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 early ValueError with valid values listed. Ruff clean; pre-existing collection errors in tests/chat/ (missing optional bedrock extras in a non---all-extras venv) are unrelated and unchanged.

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings July 28, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@denispetre

Copy link
Copy Markdown
Contributor Author

Folded into #1009 per review preference (commit aa36733) — one PR carries the testcase payloads, the workflow flavor input, and the get_chat_model string coercion together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants