diff --git a/examples/experimental/litellm/src/switchyard_litellm/client.py b/examples/experimental/litellm/src/switchyard_litellm/client.py index dc0286c1f..7ee069948 100644 --- a/examples/experimental/litellm/src/switchyard_litellm/client.py +++ b/examples/experimental/litellm/src/switchyard_litellm/client.py @@ -236,10 +236,10 @@ def _payload(request: Mapping[str, object], model: str) -> dict[str, Any]: tool_choice = _tool_choice(request) if tool_choice is not None: payload["tool_choice"] = tool_choice - for source, target in (("temperature", "temperature"), ("top_p", "top_p")): - value = sampling.get(source) + for key in ("temperature", "top_p"): + value = sampling.get(key) if value is not None: - payload[target] = value + payload[key] = value max_tokens = output.get("max_output_tokens") if max_tokens is not None: payload["max_completion_tokens"] = max_tokens diff --git a/examples/experimental/litellm/tests/test_payload_sampling.py b/examples/experimental/litellm/tests/test_payload_sampling.py new file mode 100644 index 000000000..edd23f68f --- /dev/null +++ b/examples/experimental/litellm/tests/test_payload_sampling.py @@ -0,0 +1,11 @@ +from switchyard_litellm.client import _payload + + +def test_sampling_temperature_and_top_p_forwarded() -> None: + request = { + "messages": [{"role": "user", "content": [{"type": "text", "text": "hi"}]}], + "sampling": {"temperature": 0.5, "top_p": 0.9}, + } + payload = _payload(request, "strong") + assert payload["temperature"] == 0.5 + assert payload["top_p"] == 0.9