Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sgl-model-gateway/bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../.."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions sgl-model-gateway/bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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>()?;
Expand All @@ -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(())
}
Loading