@@ -323,6 +323,9 @@ def extract_tool_call_required_streaming(
323
323
delta_text : str ,
324
324
function_name_returned : bool ,
325
325
) -> tuple [Optional [DeltaMessage ], bool ]:
326
+ if current_text is None or current_text == "" :
327
+ # if the current text is empty, we cannot parse it
328
+ return None , function_name_returned
326
329
try :
327
330
obj = partial_json_parser .loads (current_text )
328
331
except partial_json_parser .core .exceptions .MalformedJSON :
@@ -649,10 +652,18 @@ async def chat_completion_stream_generator(
649
652
current_text = previous_text + delta_text
650
653
fn_name_returned = function_name_returned [i ]
651
654
655
+ if self .reasoning_parser :
656
+ _ , content = \
657
+ reasoning_parser .extract_reasoning_content (
658
+ current_text ,
659
+ request
660
+ )
661
+ else :
662
+ content = current_text
652
663
delta_message , function_name_returned [i ] = (
653
664
self .extract_tool_call_required_streaming (
654
665
previous_text = previous_text ,
655
- current_text = current_text ,
666
+ current_text = content ,
656
667
delta_text = delta_text ,
657
668
function_name_returned = fn_name_returned ))
658
669
@@ -932,8 +943,7 @@ async def chat_completion_full_generator(
932
943
else :
933
944
logprobs = None
934
945
auto_tools_called = False
935
- reasoning_content = None
936
- content = output .text
946
+
937
947
if self .reasoning_parser :
938
948
try :
939
949
reasoning_parser = self .reasoning_parser (tokenizer )
@@ -945,6 +955,9 @@ async def chat_completion_full_generator(
945
955
reasoning_content , content = (
946
956
reasoning_parser .extract_reasoning_content (
947
957
output .text , request = request ))
958
+ else :
959
+ reasoning_content = None
960
+ content = output .text
948
961
949
962
# if auto tools are not enabled, and a named tool choice using
950
963
# outlines is not being used
@@ -978,6 +991,7 @@ async def chat_completion_full_generator(
978
991
979
992
# the fields of FunctionDefinition are a superset of the
980
993
# tool call outputs and can be used for parsing
994
+ assert content is not None
981
995
tool_calls = TypeAdapter (
982
996
list [FunctionDefinition ]).validate_json (content )
983
997
message = ChatMessage (
0 commit comments