1717from slm_server .utils .ids import gen_id
1818
1919_THINK_RE = re .compile (r"<think>(.*?)</think>" , re .DOTALL )
20- _TOOL_CALL_RE = re .compile (
21- r"<tool_call>\s*(\{.*?\})\s*</tool_call>" , re .DOTALL
22- )
20+ _TOOL_CALL_RE = re .compile (r"<tool_call>\s*(\{.*?\})\s*</tool_call>" , re .DOTALL )
2321
2422
2523def extract_reasoning (content : str ) -> tuple [str | None , str ]:
@@ -151,9 +149,7 @@ def __init__(self, *, model_id: str | None = None) -> None:
151149
152150 # -- public API ----------------------------------------------------------
153151
154- def process_chunk (
155- self , chunk : dict [str , Any ]
156- ) -> list [dict [str , Any ]]:
152+ def process_chunk (self , chunk : dict [str , Any ]) -> list [dict [str , Any ]]:
157153 """Process one streaming chunk, returning zero or more output chunks."""
158154 self ._last_chunk_template = chunk
159155
@@ -178,8 +174,11 @@ def process_chunk(
178174 "tool_calls" if self ._had_tool_calls else orig_finish
179175 )
180176 else :
181- result .append (self ._rewrite_finish (chunk ) if self ._had_tool_calls
182- else self ._stamp (copy .deepcopy (chunk )))
177+ result .append (
178+ self ._rewrite_finish (chunk )
179+ if self ._had_tool_calls
180+ else self ._stamp (copy .deepcopy (chunk ))
181+ )
183182
184183 return result
185184
@@ -193,9 +192,7 @@ def flush(self) -> list[dict[str, Any]]:
193192
194193 # -- internals -----------------------------------------------------------
195194
196- def _consume_text (
197- self , text : str , chunk : dict [str , Any ]
198- ) -> list [dict [str , Any ]]:
195+ def _consume_text (self , text : str , chunk : dict [str , Any ]) -> list [dict [str , Any ]]:
199196 """Feed *text* through the tag-detection state machine.
200197
201198 Batches consecutive characters for the same state into single chunks
@@ -273,9 +270,7 @@ def _emit_batch(self, text: str) -> list[dict[str, Any]]:
273270 self ._tool_call_buf += text
274271 return []
275272
276- def _finish_tool_call (
277- self , chunk : dict [str , Any ]
278- ) -> list [dict [str , Any ]]:
273+ def _finish_tool_call (self , chunk : dict [str , Any ]) -> list [dict [str , Any ]]:
279274 """Parse the accumulated JSON and emit a ``tool_calls`` delta."""
280275 raw = self ._tool_call_buf .strip ()
281276 self ._tool_call_buf = ""
0 commit comments