Skip to content

Commit 624bf64

Browse files
committed
feat: extend to support gemini as well
1 parent db98302 commit 624bf64

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

posthog/ai/gemini/gemini.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import time
33
import uuid
4-
from typing import Any, Dict, Optional
4+
from typing import Any, Dict, Optional, cast
55

66
try:
77
from google import genai
@@ -36,6 +36,8 @@ class Client:
3636
)
3737
"""
3838

39+
_ph_client: PostHogClient
40+
3941
def __init__(
4042
self,
4143
api_key: Optional[str] = None,
@@ -57,11 +59,19 @@ def __init__(
5759
**kwargs: Additional arguments (for future compatibility)
5860
"""
5961
if posthog_client is None:
62+
import posthog
63+
64+
posthog.setup()
65+
self._ph_client = cast(PostHogClient, posthog.default_client)
66+
else:
67+
self._ph_client = posthog_client
68+
69+
if self._ph_client is None:
6070
raise ValueError("posthog_client is required for PostHog tracking")
6171

6272
self.models = Models(
6373
api_key=api_key,
64-
posthog_client=posthog_client,
74+
posthog_client=self._ph_client,
6575
posthog_distinct_id=posthog_distinct_id,
6676
posthog_properties=posthog_properties,
6777
posthog_privacy_mode=posthog_privacy_mode,
@@ -98,9 +108,15 @@ def __init__(
98108
**kwargs: Additional arguments (for future compatibility)
99109
"""
100110
if posthog_client is None:
101-
raise ValueError("posthog_client is required for PostHog tracking")
111+
import posthog
112+
113+
posthog.setup()
114+
self._ph_client = cast(PostHogClient, posthog.default_client)
115+
else:
116+
self._ph_client = posthog_client
102117

103-
self._ph_client = posthog_client
118+
if self._ph_client is None:
119+
raise ValueError("posthog_client is required for PostHog tracking")
104120

105121
# Store default PostHog settings
106122
self._default_distinct_id = posthog_distinct_id

0 commit comments

Comments
 (0)