55 "Please install the Anthropic SDK to use this feature: 'pip install anthropic'"
66 )
77
8- from typing import Optional , cast
8+ from typing import Optional
99
1010from posthog .ai .anthropic .anthropic import WrappedMessages
1111from posthog .ai .anthropic .anthropic_async import AsyncWrappedMessages
1212from posthog .client import Client as PostHogClient
13+ from posthog import setup
1314
1415
1516class AnthropicBedrock (anthropic .AnthropicBedrock ):
@@ -21,13 +22,7 @@ class AnthropicBedrock(anthropic.AnthropicBedrock):
2122
2223 def __init__ (self , posthog_client : Optional [PostHogClient ] = None , ** kwargs ):
2324 super ().__init__ (** kwargs )
24- if posthog_client is None :
25- import posthog
26-
27- posthog .setup ()
28- self ._ph_client = cast (PostHogClient , posthog .default_client )
29- else :
30- self ._ph_client = posthog_client
25+ self ._ph_client = posthog_client or setup ()
3126 self .messages = WrappedMessages (self )
3227
3328
@@ -40,13 +35,7 @@ class AsyncAnthropicBedrock(anthropic.AsyncAnthropicBedrock):
4035
4136 def __init__ (self , posthog_client : Optional [PostHogClient ] = None , ** kwargs ):
4237 super ().__init__ (** kwargs )
43- if posthog_client is None :
44- import posthog
45-
46- posthog .setup ()
47- self ._ph_client = cast (PostHogClient , posthog .default_client )
48- else :
49- self ._ph_client = posthog_client
38+ self ._ph_client = posthog_client or setup ()
5039 self .messages = AsyncWrappedMessages (self )
5140
5241
@@ -59,13 +48,7 @@ class AnthropicVertex(anthropic.AnthropicVertex):
5948
6049 def __init__ (self , posthog_client : Optional [PostHogClient ] = None , ** kwargs ):
6150 super ().__init__ (** kwargs )
62- if posthog_client is None :
63- import posthog
64-
65- posthog .setup ()
66- self ._ph_client = cast (PostHogClient , posthog .default_client )
67- else :
68- self ._ph_client = posthog_client
51+ self ._ph_client = posthog_client or setup ()
6952 self .messages = WrappedMessages (self )
7053
7154
@@ -78,11 +61,5 @@ class AsyncAnthropicVertex(anthropic.AsyncAnthropicVertex):
7861
7962 def __init__ (self , posthog_client : Optional [PostHogClient ] = None , ** kwargs ):
8063 super ().__init__ (** kwargs )
81- if posthog_client is None :
82- import posthog
83-
84- posthog .setup ()
85- self ._ph_client = cast (PostHogClient , posthog .default_client )
86- else :
87- self ._ph_client = posthog_client
64+ self ._ph_client = posthog_client or setup ()
8865 self .messages = AsyncWrappedMessages (self )
0 commit comments