diff --git a/sgl-model-gateway/bindings/python/Cargo.toml b/sgl-model-gateway/bindings/python/Cargo.toml index 3f88cd6958df..f44f74a9a755 100644 --- a/sgl-model-gateway/bindings/python/Cargo.toml +++ b/sgl-model-gateway/bindings/python/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.27.1", features = ["extension-module", "abi3-py38"] } tokio = { version = "1.42.0", features = ["full"] } +once_cell = "1.19" [dependencies.sgl-model-gateway] path = "../.." diff --git a/sgl-model-gateway/bindings/python/sglang_router/router_args.py b/sgl-model-gateway/bindings/python/sglang_router/router_args.py index 2eefb513a515..01d391d83a20 100644 --- a/sgl-model-gateway/bindings/python/sglang_router/router_args.py +++ b/sgl-model-gateway/bindings/python/sglang_router/router_args.py @@ -4,6 +4,8 @@ import os from typing import Dict, List, Optional +from sglang_router.sglang_router_rs import get_available_tool_call_parsers + logger = logging.getLogger(__name__) @@ -520,11 +522,13 @@ def add_cli_args( default=None, help="Specify the parser for reasoning models (e.g., deepseek-r1, qwen3)", ) + tool_call_parser_choices = get_available_tool_call_parsers() parser.add_argument( f"--{prefix}tool-call-parser", type=str, default=None, - help="Specify the parser for handling tool-call interactions", + choices=tool_call_parser_choices, + help=f"Specify the parser for tool-call interactions (e.g., json, qwen)", ) # MCP server configuration parser.add_argument( diff --git a/sgl-model-gateway/bindings/python/src/lib.rs b/sgl-model-gateway/bindings/python/src/lib.rs index 67082a618031..dbe29ebf4391 100644 --- a/sgl-model-gateway/bindings/python/src/lib.rs +++ b/sgl-model-gateway/bindings/python/src/lib.rs @@ -1,5 +1,6 @@ use pyo3::prelude::*; use sgl_model_gateway::*; +use once_cell::sync::OnceCell; use std::collections::HashMap; // Define the enums with PyO3 bindings @@ -730,6 +731,18 @@ fn get_verbose_version_string() -> String { version::get_verbose_version_string() } +/// Get the list of available tool call parsers from the Rust factory. +#[pyfunction] +fn get_available_tool_call_parsers() -> Vec { + static PARSERS: OnceCell> = OnceCell::new(); + PARSERS + .get_or_init(|| { + let factory = tool_parser::ParserFactory::new(); + factory.list_parsers() + }) + .clone() +} + #[pymodule] fn sglang_router_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; @@ -740,5 +753,6 @@ fn sglang_router_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_function(wrap_pyfunction!(get_version_string, m)?)?; m.add_function(wrap_pyfunction!(get_verbose_version_string, m)?)?; + m.add_function(wrap_pyfunction!(get_available_tool_call_parsers, m)?)?; Ok(()) }