From 6f4676ef854d4d2461969f8464f227b84d2eaac7 Mon Sep 17 00:00:00 2001 From: Xinyuan Tong <115166877+JustinTong0323@users.noreply.github.com> Date: Fri, 12 Sep 2025 22:29:35 -0700 Subject: [PATCH] fix: tool parse in large streaming chunk beginning with normal content (#10397) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- python/sglang/srt/function_call/base_format_detector.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/python/sglang/srt/function_call/base_format_detector.py b/python/sglang/srt/function_call/base_format_detector.py index 39bb92f5f..efc001d31 100644 --- a/python/sglang/srt/function_call/base_format_detector.py +++ b/python/sglang/srt/function_call/base_format_detector.py @@ -162,12 +162,9 @@ class BaseFormatDetector(ABC): try: try: - if current_text.startswith(self.bot_token): - start_idx = len(self.bot_token) - elif self.current_tool_id > 0 and current_text.startswith( - self.tool_call_separator + self.bot_token - ): - start_idx = len(self.tool_call_separator + self.bot_token) + tool_call_pos = current_text.find(self.bot_token) + if tool_call_pos != -1: + start_idx = tool_call_pos + len(self.bot_token) elif self.current_tool_id > 0 and current_text.startswith( self.tool_call_separator ):