Skip to content

Commit 7419b70

Browse files
replace jiter by partial-json-parser
1 parent 8467d41 commit 7419b70

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"sniffio",
1717
"cached-property; python_version < '3.8'",
1818
"tqdm > 4",
19-
"jiter>=0.4.0, <1",
19+
"partial-json-parser ~= 0.2.1.1.post4",
2020
]
2121
requires-python = ">= 3.7.1"
2222
classifiers = [

src/openai/lib/streaming/chat/_completions.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TYPE_CHECKING, Any, Generic, Callable, Iterable, Awaitable, AsyncIterator, cast
66
from typing_extensions import Self, Iterator, assert_never
77

8-
from jiter import from_json
8+
from partial_json_parser import parse_json # type: ignore
99

1010
from ._types import ParsedChoiceSnapshot, ParsedChatCompletionSnapshot, ParsedChatCompletionMessageSnapshot
1111
from ._events import (
@@ -406,10 +406,7 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
406406
and not choice_snapshot.message.refusal
407407
and is_given(self._rich_response_format)
408408
):
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)
413410

414411
for tool_call_chunk in choice.delta.tool_calls or []:
415412
tool_call_snapshot = (choice_snapshot.message.tool_calls or [])[tool_call_chunk.index]
@@ -424,10 +421,7 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
424421
and input_tool.get("function", {}).get("strict")
425422
and tool_call_snapshot.function.arguments
426423
):
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)
431425
elif TYPE_CHECKING: # type: ignore[unreachable]
432426
assert_never(tool_call_snapshot)
433427

0 commit comments

Comments
 (0)