Skip to content

Commit 828ce8c

Browse files
committed
feat: add ability to specify params to drop
Some LLMs don't support all params that clients could send. This MR gives the administrator the ability to filter those out Similar to https://docs.litellm.ai/docs/completion/drop_params Signed-off-by: Max Wittig <[email protected]>
1 parent 6b0a04a commit 828ce8c

File tree

6 files changed

+97
-92
lines changed

6 files changed

+97
-92
lines changed

src/vllm_router/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ def initialize_all(app: FastAPI, args):
199199
if args.callbacks:
200200
configure_custom_callbacks(args.callbacks, app)
201201

202+
app.state.drop_params = parse_comma_separated_args(args.drop_params)
203+
202204
initialize_routing_logic(
203205
args.routing_logic,
204206
session_key=args.session_key,

src/vllm_router/parsers/parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ def parse_args():
240240
help="The request rewriter to use. Default is 'noop' (no rewriting).",
241241
)
242242

243+
# Drop params arguments
244+
parser.add_argument(
245+
"--drop-params",
246+
type=str,
247+
default=None,
248+
help="Comma-separated list of OpenAI parameters to drop from requests. "
249+
"This allows dropping unsupported parameters by your LLM provider. "
250+
"Example: 'frequency_penalty,logit_bias'",
251+
)
252+
243253
# Batch API
244254
# TODO(gaocegege): Make these batch api related arguments to a separate config.
245255
parser.add_argument(

src/vllm_router/services/request_service/request.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ async def route_general_request(
203203
status_code=400, detail="Request body is not JSON parsable."
204204
)
205205

206+
if hasattr(request.app.state, "drop_params") and request.app.state.drop_params:
207+
for param in request.app.state.drop_params:
208+
request_json.pop(param, None)
209+
logger.debug(f"Dropped param {param} from request")
210+
request_body = json.dumps(request_json)
211+
update_content_length(request, request_body)
212+
206213
service_discovery = get_service_discovery()
207214
endpoints = service_discovery.get_endpoint_info()
208215

tests/e2e/run-static-discovery-routing-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ start_router() {
9999
--decode-model-labels "decode" \
100100
--static-model-labels "prefill,decode" \
101101
--session-key "$SESSION_KEY" \
102-
--routing-logic "$routing_logic" > "$log_file" 2>&1 &
102+
--routing-logic "$routing_logic" \
103+
--drop-params "test-param-to-drop" > "$log_file" 2>&1 &
103104

104105
ROUTER_PID=$!
105106
print_status "Router started with PID: $ROUTER_PID"

tests/e2e/test-routing.py

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,20 @@ def _save_routing_lines(
157157
)
158158
return False
159159

160-
def send_request(self, request_id: str, prompt: str) -> bool:
160+
def send_request(
161+
self, request_id: str, prompt: str, custom_payload: dict = None
162+
) -> bool:
161163
"""Send a single request and track which endpoint it goes to"""
162164
try:
163-
payload = {
164-
"model": self.model,
165-
"prompt": prompt,
166-
"temperature": 0.7,
167-
"max_tokens": 10,
168-
}
165+
if custom_payload is not None:
166+
payload = custom_payload
167+
else:
168+
payload = {
169+
"model": self.model,
170+
"prompt": prompt,
171+
"temperature": 0.7,
172+
"max_tokens": 10,
173+
}
169174

170175
headers = {
171176
"Content-Type": "application/json",
@@ -542,6 +547,43 @@ def test_chat_completions(self) -> bool:
542547
print_error(f"❌ Chat completions failed: {e} payload: {payload}")
543548
return False
544549

550+
def test_drop_params(self) -> bool:
551+
"""Test that the router drops specified parameters from requests"""
552+
print_status("🧪 Testing drop_params functionality")
553+
554+
# Send a request with parameters that should be dropped
555+
try:
556+
# Use the existing send_request method with custom payload to test drop_params
557+
custom_payload = {
558+
"model": self.model,
559+
"prompt": "Test prompt with parameters to drop",
560+
"temperature": 0.7,
561+
"max_tokens": 10,
562+
"test-param-to-drop": 0.5, # This should be dropped
563+
}
564+
565+
# Send request using existing method with custom payload
566+
if not self.send_request(
567+
"test-drop-params-request",
568+
"Test prompt with parameters to drop",
569+
custom_payload,
570+
):
571+
print_error("❌ Drop params test request failed")
572+
return False
573+
574+
# Check router logs for evidence that parameters were dropped
575+
content = self._read_log_file()
576+
if content is not None:
577+
if "Dropped param test-param-to-drop from request" in str(content):
578+
print_status("✅ Drop params test request completed successfully")
579+
return True
580+
581+
print_error("❌ Drop params test request failed")
582+
return False
583+
except Exception as e:
584+
print_error(f"❌ Unexpected error in drop params test: {e}")
585+
return False
586+
545587
def run_test(self) -> bool:
546588
"""Run the complete routing test"""
547589
try:
@@ -559,6 +601,10 @@ def run_test(self) -> bool:
559601
if not self.test_chat_completions():
560602
return False
561603

604+
# Test drop_params functionality
605+
if not self.test_drop_params():
606+
return False
607+
562608
# Test routing logic
563609
test_runners = {
564610
"roundrobin": self.test_roundrobin_routing,

0 commit comments

Comments
 (0)