@@ -219,7 +219,8 @@ def _extract_json_str(self, current_text: str) -> str:
219
219
Extract JSON string from the current text between tool call delimiters.
220
220
221
221
Extracts the content between <|tools_prefix|> and <|tools_suffix|> tokens.
222
- If the suffix is not present (incomplete streaming), returns everything after the prefix.
222
+ If the suffix is not present (incomplete streaming),
223
+ returns everything after the prefix.
223
224
224
225
Args:
225
226
current_text: The accumulated model output text.
@@ -228,7 +229,8 @@ def _extract_json_str(self, current_text: str) -> str:
228
229
The extracted JSON string without the delimiter tokens.
229
230
230
231
Example:
231
- >>> current_text = 'Some text <|tools_prefix|>[{"func": {"arg": "val"}}]<|tools_suffix|>'
232
+ >>> current_text = 'Some text <|tools_prefix|>
233
+ [{"func": {"arg": "val"}}]<|tools_suffix|>'
232
234
>>> self._extract_json_str(current_text)
233
235
'[{"func": {"arg": "val"}}]'
234
236
@@ -282,10 +284,13 @@ def _parse_partial_json(self, json_str: str) -> list[dict]:
282
284
283
285
def _finalize_previous_tool (self ) -> DeltaMessage | None :
284
286
"""
285
- Finalize any remaining arguments from the previous tool before moving to the next one.
287
+ Finalize any remaining arguments
288
+ from the previous tool before moving to the next one.
286
289
287
- When transitioning to a new tool in the array, this ensures all arguments
288
- from the current tool that haven't been streamed yet are sent in one final delta.
290
+ When transitioning to a new tool in the array,
291
+ this ensures all arguments
292
+ from the current tool that haven't been
293
+ streamed yet are sent in one final delta.
289
294
290
295
This is necessary because when a new tool appears, we may have parsed additional
291
296
arguments for the previous tool that weren't yet sent to the client.
@@ -385,7 +390,8 @@ def _stream_arguments(
385
390
as they become available. Tracks what has already been sent and only streams
386
391
the difference.
387
392
388
- The tool call format is expected to be: {"function_name": {"arg1": "val1", ...}}
393
+ The tool call format is expected to be:
394
+ {"function_name": {"arg1": "val1", ...}}
389
395
390
396
Args:
391
397
current_tool_call: A dictionary with a single key (function name) and
@@ -470,8 +476,10 @@ def _calculate_argument_diff(
470
476
- Arguments haven't changed since last iteration
471
477
472
478
Example:
473
- Iteration 1: args_json = '{"x": 5' -> sent = 0 -> returns '{"x": 5'
474
- Iteration 2: args_json = '{"x": 5, "y": 10}' -> sent = 7 -> returns ', "y": 10}'
479
+ Iteration 1: args_json =
480
+ '{"x": 5' -> sent = 0 -> returns '{"x": 5'
481
+ Iteration 2: args_json =
482
+ '{"x": 5, "y": 10}' -> sent = 7 -> returns ', "y": 10}'
475
483
"""
476
484
is_complete_call = is_complete_json (json_str )
477
485
0 commit comments