From 151e287d1af60e4e40fe4ae653fed440c93e8264 Mon Sep 17 00:00:00 2001 From: Yi Zhang <1109276519@qq.com> Date: Sat, 13 Sep 2025 01:28:54 +0800 Subject: [PATCH] fix: add fast path for function call (#9023) Co-authored-by: tazjin --- python/sglang/srt/function_call/function_call_parser.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/sglang/srt/function_call/function_call_parser.py b/python/sglang/srt/function_call/function_call_parser.py index 18fe488e4..e28f4f5cf 100644 --- a/python/sglang/srt/function_call/function_call_parser.py +++ b/python/sglang/srt/function_call/function_call_parser.py @@ -69,6 +69,8 @@ class FunctionCallParser: Returns: True if the text contains a tool call, False otherwise """ + if not self.tools: + return False return self.detector.has_tool_call(text) def parse_non_stream(self, full_text: str) -> Tuple[str, list[ToolCallItem]]: @@ -83,6 +85,8 @@ class FunctionCallParser: - The remaining text after parsing that was not consumed by the detector (can be treated as normal text) - A list of tool calls parsed from the text """ + if not self.tools: + return full_text, [] parsed_result = self.detector.detect_and_parse(full_text, self.tools) tool_call_list = parsed_result.calls if tool_call_list: @@ -102,6 +106,8 @@ class FunctionCallParser: - The normal text that should be displayed to the user - A list of tool calls parsed from the chunk """ + if not self.tools: + return chunk_text, [] final_normal_text = "" final_calls = []