1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
From: =?utf-8?q?Antoine_Beaupr=C3=A9?= <anarcat@debian.org>
Date: Tue, 6 Jan 2026 14:12:20 -0500
Subject: make jiter optional
---
src/anthropic/lib/streaming/_beta_messages.py | 5 ++++-
src/anthropic/lib/streaming/_beta_types.py | 7 +++++--
src/anthropic/lib/streaming/_messages.py | 5 ++++-
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/anthropic/lib/streaming/_beta_messages.py b/src/anthropic/lib/streaming/_beta_messages.py
index a760dce..cb61186 100644
--- a/src/anthropic/lib/streaming/_beta_messages.py
+++ b/src/anthropic/lib/streaming/_beta_messages.py
@@ -478,7 +478,10 @@ def accumulate_event(
content.text += event.delta.text
elif event.delta.type == "input_json_delta":
if isinstance(content, TRACKS_TOOL_INPUT):
- from jiter import from_json
+ try:
+ from jiter import from_json
+ except ImportError:
+ from pydantic_core import from_json
# we need to keep track of the raw JSON string as well so that we can
# re-parse it for each delta, for now we just store it as an untyped
diff --git a/src/anthropic/lib/streaming/_beta_types.py b/src/anthropic/lib/streaming/_beta_types.py
index 09ade76..bd2e216 100644
--- a/src/anthropic/lib/streaming/_beta_types.py
+++ b/src/anthropic/lib/streaming/_beta_types.py
@@ -1,7 +1,10 @@
from typing import TYPE_CHECKING, Any, Dict, Union, Generic, cast
from typing_extensions import List, Literal, Annotated
-import jiter
+try:
+ from jiter import from_json
+except ImportError:
+ from pydantic_core import from_json
from ..._models import BaseModel, GenericModel
from ...types.beta import (
@@ -28,7 +31,7 @@ class ParsedBetaTextEvent(BaseModel):
"""The entire accumulated text"""
def parsed_snapshot(self) -> Dict[str, Any]:
- return cast(Dict[str, Any], jiter.from_json(self.snapshot.encode("utf-8"), partial_mode="trailing-strings"))
+ return cast(Dict[str, Any], from_json(self.snapshot.encode("utf-8"), partial_mode="trailing-strings"))
class BetaCitationEvent(BaseModel):
diff --git a/src/anthropic/lib/streaming/_messages.py b/src/anthropic/lib/streaming/_messages.py
index 857f973..5adb1a9 100644
--- a/src/anthropic/lib/streaming/_messages.py
+++ b/src/anthropic/lib/streaming/_messages.py
@@ -438,7 +438,10 @@ def accumulate_event(
content.text += event.delta.text
elif event.delta.type == "input_json_delta":
if isinstance(content, TRACKS_TOOL_INPUT):
- from jiter import from_json
+ try:
+ from jiter import from_json
+ except ImportError:
+ from pydantic_core import from_json
# we need to keep track of the raw JSON string as well so that we can
# re-parse it for each delta, for now we just store it as an untyped
|