feat: rust sglang server openai apis (#33103)

Co-authored-by: Rain Jiang <rain-jiang@outlook.com>
This commit is contained in:
Chengyu Lin
2026-08-02 23:13:44 -07:00
committed by GitHub
co-authored by Rain Jiang
parent 0bf0640b9d
commit e00f32ed4f
28 changed files with 7615 additions and 217 deletions
@@ -11,6 +11,7 @@ from sglang.test.test_utils import (
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
DEFAULT_URL_FOR_TEST,
CustomTestCase,
is_rust_server_built,
popen_launch_server,
)
@@ -62,7 +63,9 @@ class TestOpenAIServerFunctionCalling(CustomTestCase):
def test_function_calling_format(self):
"""
Test: Whether the function call format returned by the AI is correct.
When returning a tool call, message.content should be None, and tool_calls should be a list.
Require a tool call so this tests the response format rather than the
model's stochastic decision to call a tool. message.content should be
None, and tool_calls should be a list.
"""
client = openai.Client(api_key=self.api_key, base_url=self.base_url)
@@ -102,6 +105,7 @@ class TestOpenAIServerFunctionCalling(CustomTestCase):
top_p=0.8,
stream=False,
tools=tools,
tool_choice="required",
)
tool_calls = response.choices[0].message.tool_calls
@@ -914,6 +918,54 @@ class TestOpenAIPythonicFunctionCalling(CustomTestCase):
)
@unittest.skipUnless(
is_rust_server_built(),
"embedded rust server extension not built",
)
class TestOpenAIFunctionCallingWithRust(TestOpenAIServerFunctionCalling):
"""Run the registered unary/streaming function-call suite through Rust."""
@classmethod
def setUpClass(cls):
cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
cls.base_url = DEFAULT_URL_FOR_TEST
cls.api_key = "sk-123456"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
api_key=cls.api_key,
other_args=["--tool-call-parser", "llama3"],
env={"SGLANG_RUST_SERVER": "1"},
)
cls.base_url += "/v1"
cls.tokenizer = get_tokenizer(cls.model)
@unittest.skipUnless(
is_rust_server_built(),
"embedded rust server extension not built",
)
class TestOpenAIPythonicFunctionCallingWithRust(TestOpenAIPythonicFunctionCalling):
"""Run Pythonic unary/streaming tool calls through Rust."""
@classmethod
def setUpClass(cls):
cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
cls.base_url = DEFAULT_URL_FOR_TEST
cls.api_key = "sk-123456"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
api_key=cls.api_key,
other_args=["--tool-call-parser", "pythonic"],
env={"SGLANG_RUST_SERVER": "1"},
)
cls.base_url += "/v1"
cls.tokenizer = get_tokenizer(cls.model)
# Skip for ci test
# class TestGLM45ServerFunctionCalling(TestOpenAIServerFunctionCalling):
# @classmethod