fix: simplify identical source/target loop in payload builder - #356
Conversation
Summary
Replace the explicit source/target tuple loop where source and target are always the same key with a single-key loop, improving readability without changing behavior.
Root cause
The loop copied sampling values with a source-to-target mapping, but the keys ('temperature', 'top_p') were identical on both sides, so the mapping added noise without adding flexibility.
Fix
Iterate over the keys directly. Behavior is preserved: values are still copied only when present.
Testing
- pytest tests/test_client.py tests/test_payload_sampling.py -v: 34 passed
- Full pytest examples/experimental/litellm/tests/ has one pre-existing failure unrelated to this change: test_stage_router_drives_both_litellm_targets (KeyError: 'selected_model').
- mypy examples/experimental/litellm/src/switchyard_litellm/client.py reports one pre-existing [no-redef] error on line 127 (also present on unmodified main).
Why existing tests missed it
No functional change; the new regression test explicitly verifies temperature/top_p are forwarded through _payload.
Contributor guidelines
- DCO sign-off: included (Signed-off-by).
- Squash: one commit.
Fixes #2094
Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
WalkthroughThe LiteLLM payload mapping now iterates directly over ChangesLiteLLM sampling payload
Estimated code review effort: 1 (Trivial) | ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
examples/experimental/litellm/tests/test_payload_sampling.py (1)
4-4: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a docstring to the test entry point.
test_sampling_temperature_and_top_p_forwardedis a public pytest function without a docstring. Add a concise docstring that states it verifies forwarding ofsampling.temperatureandsampling.top_p.As per coding guidelines: “Add concise triple-quoted docstrings for public functions, classes, methods, and API entry points.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/experimental/litellm/tests/test_payload_sampling.py` at line 4, Add a concise triple-quoted docstring to the test_sampling_temperature_and_top_p_forwarded pytest function stating that it verifies forwarding of sampling.temperature and sampling.top_p, without changing the test behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@examples/experimental/litellm/tests/test_payload_sampling.py`:
- Line 4: Add a concise triple-quoted docstring to the
test_sampling_temperature_and_top_p_forwarded pytest function stating that it
verifies forwarding of sampling.temperature and sampling.top_p, without changing
the test behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 28e61915-d56e-4c61-97a7-0987c95c3d1d
📒 Files selected for processing (2)
examples/experimental/litellm/src/switchyard_litellm/client.pyexamples/experimental/litellm/tests/test_payload_sampling.py
fix: simplify identical source/target loop in payload builder
Root cause
The loop copied sampling values with a source-to-target mapping, but the keys (
temperature,top_p) were identical on both sides, so the mapping added noise without adding flexibility.Fix
Iterate over the keys directly. Behavior is preserved: values are still copied only when present.
Testing
pytest tests/test_client.py tests/test_payload_sampling.py -v: 34 passedpytesthas one pre-existing failure unrelated to this change:test_stage_router_drives_both_litellm_targets.mypyreports one pre-existingno-redeferror on line 127 (also present on unmodifiedmain).Why existing tests missed it
No functional change; the new regression test explicitly verifies
temperature/top_pare forwarded through the payload builder.Contributor guidelines
Summary by CodeRabbit
Bug Fixes
Tests