feat(translation): prepare requests for routed targets - #455
Conversation
9524bbc to
7f74985
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. WalkthroughThe translation crate exposes request preparation for target models and optional prompts. It patches preserved OpenAI Chat, OpenAI Responses, and Anthropic bodies, handles custom formats, restores preservation metadata, and adds cross-format and safety tests. ChangesRequest preparation
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to The translation change is localized and preserves provider request fields while applying routed target metadata and prompts. No actionable merge-blocking risk remains beyond normal checks and review. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
Signed-off-by: Alex Fournier <afournier@nvidia.com>
7f74985 to
55d2a22
Compare
Summary
Adds one translation-layer operation that stamps a routed target and optionally prepends that target's system prompt without losing provider-specific request fields.
This is 1 of 3 for SWITCH-1253. It establishes the wire-format operation only; it does not add target configuration or change router behavior by itself.
Before
Routing hosts changed only the normalized request:
The normalized request may also retain an exact provider body so same-format forwarding can preserve fields Switchyard does not model. Updating only the normalized request could leave that body with the route alias and no target prompt. Dropping the body avoided stale replay, but also dropped provider-only fields.
After
Target selection and prompt insertion are one provider-aware operation:
The helper updates the normalized request and any preserved OpenAI Chat, OpenAI Responses, or Anthropic Messages body together. Existing system content and provider-only fields remain intact, while same-format encoding cannot restore the route alias or omit the target prompt.
For a custom exact format, an unprompted exact body is left untouched; its codec remains responsible for stamping the wire-level model. If a configured prompt cannot be patched safely, Switchyard discards the stale exact replay and encodes from the normalized request.
Why this belongs in translation
Libsy decides which target and prompt apply. The translation crate knows how each provider represents model and system content. Keeping that mutation here gives libsy, the native server, and custom hosts one implementation instead of separate OpenAI and Anthropic patching rules.
There are no binding changes in this PR because it is the low-level operation used by the libsy layer in #463.
Scope
prepare_request_for_target(...)helper.Validation
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningscargo test -p switchyard-translationmaturin develop; 143 Python tests, ruff, mypy, and strict docs passed.Suggested review order
crates/switchyard-translation/src/util.rs— the operation and the three built-in provider-body adapterscrates/switchyard-translation/tests/request_translation.rs— preservation and failure boundariescrates/switchyard-translation/src/lib.rs— public exportStack
targets.*.system_prompt, compatibility, docs, and integration testsThis PR is one signed commit:
7f749851(3 files, +313/-5). The two dependent PRs remain drafts and currently show cumulative diffs againstmain; their unique commits and line counts are called out in their descriptions.Summary by CodeRabbit
New Features
Bug Fixes