Skip to content

Commit 6472419

Browse files
committed
fix: anthropic types update
1 parent ce4be32 commit 6472419

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

parea/wrapper/anthropic/anthropic.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from datetime import datetime
66

77
from anthropic import AsyncMessageStreamManager, AsyncStream, Client, MessageStreamManager, Stream
8-
from anthropic.types import ContentBlockDeltaEvent, Message, MessageDeltaEvent, MessageStartEvent, TextBlock
8+
from anthropic.types import ContentBlockDeltaEvent, Message, MessageDeltaEvent, MessageStartEvent, TextBlock, \
9+
InputJSONDelta, ToolUseBlock
910

1011
from parea.cache.cache import Cache
1112
from parea.helpers import timezone_aware_now
@@ -43,8 +44,6 @@ def init(self, log: Callable, cache: Cache, client: Client):
4344
def resolver(trace_id: str, _args: Sequence[Any], kwargs: Dict[str, Any], response: Optional[Message]) -> Optional[Any]:
4445
if response:
4546
if len(response.content) > 1:
46-
from anthropic.types.beta.tools import ToolUseBlock
47-
4847
output_list = []
4948
for content in response.content:
5049
if isinstance(content, TextBlock):
@@ -185,7 +184,10 @@ def _update_accumulator_streaming(accumulator, info_from_response, chunk):
185184
if isinstance(chunk, MessageStartEvent):
186185
info_from_response["input_tokens"] = chunk.message.usage.input_tokens
187186
elif isinstance(chunk, ContentBlockDeltaEvent):
188-
accumulator["content"].append(chunk.delta.text)
187+
if isinstance(chunk.delta, InputJSONDelta):
188+
accumulator["content"].append(chunk.delta.partial_json)
189+
else:
190+
accumulator["content"].append(chunk.delta.text)
189191
if not info_from_response.get("first_token_timestamp"):
190192
info_from_response["first_token_timestamp"] = timezone_aware_now()
191193
elif isinstance(chunk, MessageDeltaEvent):

0 commit comments

Comments
 (0)