Skip to content

Commit 3777103

Browse files
authored
Merge pull request #1052 from parea-ai/fix-anthropic-types
fix: import anthropic json delta type
2 parents 0517b1f + 4ea64b5 commit 3777103

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

cookbook/anthropic/tracing_anthropic_tool_use.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,24 @@
1717

1818

1919
def anthropic_sync(create_kwargs):
20-
message = client.beta.tools.messages.create(**create_kwargs)
20+
message = client.messages.create(**create_kwargs)
2121
print(message.content)
2222

2323

24+
def anthropic_sync_stream(create_kwargs):
25+
message = client.messages.create(stream=True, **create_kwargs)
26+
for m in message:
27+
print(m)
28+
29+
2430
async def async_anthropic(create_kwargs):
25-
message = await aclient.beta.tools.messages.create(**create_kwargs)
31+
message = await aclient.messages.create(**create_kwargs)
2632
print(message.content)
2733

2834

2935
if __name__ == "__main__":
3036
anthropic_sync(single_tool_use)
37+
anthropic_sync_stream(single_tool_use)
3138
anthropic_sync(multiple_tool_use)
3239
anthropic_sync(missing_information)
3340
# asyncio.run(async_anthropic(single_tool_use))

parea/wrapper/anthropic/anthropic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from datetime import datetime
66

77
from anthropic import AsyncMessageStreamManager, AsyncStream, Client, MessageStreamManager, Stream
8-
from anthropic.types import ContentBlockDeltaEvent, InputJSONDelta, Message, MessageDeltaEvent, MessageStartEvent, TextBlock, ToolUseBlock
8+
from anthropic.types import ContentBlockDeltaEvent, Message, MessageDeltaEvent, MessageStartEvent, TextBlock, ToolUseBlock
9+
10+
try:
11+
from anthropic.types import InputJSONDelta
12+
except ImportError:
13+
from anthropic.types import InputJsonDelta as InputJSONDelta
914

1015
from parea.cache.cache import Cache
1116
from parea.helpers import timezone_aware_now

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
66
[tool.poetry]
77
name = "parea-ai"
88
packages = [{ include = "parea" }]
9-
version = "0.2.202"
9+
version = "0.2.203"
1010
description = "Parea python sdk"
1111
readme = "README.md"
1212
authors = ["joel-parea-ai <[email protected]>"]

0 commit comments

Comments
 (0)