Skip to content

Commit ce957f1

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 a4de81a commit ce957f1

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/vllm_router/app.py

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

200+
app.state.drop_params = parse_comma_separated_args(args.drop_params)
201+
200202
initialize_routing_logic(
201203
args.routing_logic,
202204
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
@@ -228,6 +228,16 @@ def parse_args():
228228
help="The request rewriter to use. Default is 'noop' (no rewriting).",
229229
)
230230

231+
# Drop params arguments
232+
parser.add_argument(
233+
"--drop-params",
234+
type=str,
235+
default=None,
236+
help="Comma-separated list of OpenAI parameters to drop from requests. "
237+
"This allows dropping unsupported parameters by your LLM provider. "
238+
"Example: 'frequency_penalty,logit_bias'",
239+
)
240+
231241
# Batch API
232242
# TODO(gaocegege): Make these batch api related arguments to a separate config.
233243
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
# TODO (ApostaC): merge two awaits into one
207214
service_discovery = get_service_discovery()
208215
endpoints = service_discovery.get_endpoint_info()

0 commit comments

Comments
 (0)