5
5
from typing import TYPE_CHECKING , Any , Generic , Callable , Iterable , Awaitable , AsyncIterator , cast
6
6
from typing_extensions import Self , Iterator , assert_never
7
7
8
- from jiter import from_json
8
+ from partial_json_parser import parse_json # type: ignore
9
9
10
10
from ._types import ParsedChoiceSnapshot , ParsedChatCompletionSnapshot , ParsedChatCompletionMessageSnapshot
11
11
from ._events import (
@@ -406,10 +406,7 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
406
406
and not choice_snapshot .message .refusal
407
407
and is_given (self ._rich_response_format )
408
408
):
409
- choice_snapshot .message .parsed = from_json (
410
- bytes (choice_snapshot .message .content , "utf-8" ),
411
- partial_mode = True ,
412
- )
409
+ choice_snapshot .message .parsed = parse_json (choice_snapshot .message .content )
413
410
414
411
for tool_call_chunk in choice .delta .tool_calls or []:
415
412
tool_call_snapshot = (choice_snapshot .message .tool_calls or [])[tool_call_chunk .index ]
@@ -424,10 +421,7 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
424
421
and input_tool .get ("function" , {}).get ("strict" )
425
422
and tool_call_snapshot .function .arguments
426
423
):
427
- tool_call_snapshot .function .parsed_arguments = from_json (
428
- bytes (tool_call_snapshot .function .arguments , "utf-8" ),
429
- partial_mode = True ,
430
- )
424
+ tool_call_snapshot .function .parsed_arguments = parse_json (tool_call_snapshot .function .arguments )
431
425
elif TYPE_CHECKING : # type: ignore[unreachable]
432
426
assert_never (tool_call_snapshot )
433
427
0 commit comments