@@ -261,24 +261,27 @@ def _generate_delta_tool_call(self,
261
261
self .streaming_state = StreamingState .PARSING_NAME
262
262
delta_text = delta_text .replace (self .bot_token , "" , 1 )
263
263
if self .streaming_state == StreamingState .PARSING_NAME :
264
+ if self .current_tool_name is None :
265
+ self .current_tool_name = ""
264
266
# The name stops where the arguments start
265
267
# And the arguments start with the `{` char
266
268
if "{" in delta_text :
267
269
delta_function_name = delta_text .split ("{" )[0 ]
270
+ self .current_tool_name += delta_function_name
268
271
delta_text = delta_text [len (delta_function_name ):]
269
272
self .streaming_state = StreamingState .PARSING_ARGUMENTS
270
273
else :
271
- delta_function_name = delta_text
272
- return [
273
- DeltaToolCall (
274
+ # we want to send the tool name once it's complete
275
+ self .current_tool_name += delta_text
276
+ if tool_id is not None :
277
+ return [
278
+ DeltaToolCall (
274
279
index = self .current_tool_id ,
275
280
type = "function" ,
276
- id = tool_id ,
277
- function = DeltaFunctionCall (
278
- name = delta_function_name ).model_dump (
279
- exclude_none = True ),
280
- )
281
- ]
281
+ id = tool_id
282
+ )]
283
+ else :
284
+ return []
282
285
if self .streaming_state == StreamingState .PARSING_ARGUMENTS :
283
286
next_function_text = None
284
287
if self .bot_token in delta_text :
@@ -297,11 +300,12 @@ def _generate_delta_tool_call(self,
297
300
type = "function" ,
298
301
id = tool_id ,
299
302
function = DeltaFunctionCall (
300
- name = delta_function_name ,
303
+ name = self . current_tool_name ,
301
304
arguments = delta_arguments ).model_dump (
302
305
exclude_none = True ),
303
306
)
304
307
]
308
+ self .current_tool_name = None
305
309
if next_function_text :
306
310
ret += self ._generate_delta_tool_call (next_function_text )
307
311
return ret
0 commit comments