[model-gateway] Dynamically Populate Tool Call Parser Choices (#14807)

This commit is contained in:
Wenyi Xu
2025-12-10 22:04:22 +08:00
committed by GitHub
parent 766476f52a
commit d7f6320bb8
3 changed files with 20 additions and 1 deletions

View File

@@ -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 = "../.."

View File

@@ -4,6 +4,8 @@ import logging
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 @@ class RouterArgs:
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(

View File

@@ -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<String> {
static PARSERS: OnceCell<Vec<String>> = 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::<PolicyType>()?;
@@ -740,5 +753,6 @@ fn sglang_router_rs(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Router>()?;
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(())
}