posthoganalytics 6.7.11__py3-none-any.whl → 6.7.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- posthoganalytics/ai/langchain/callbacks.py +16 -3
- posthoganalytics/integrations/django.py +29 -0
- posthoganalytics/version.py +1 -1
- {posthoganalytics-6.7.11.dist-info → posthoganalytics-6.7.13.dist-info}/METADATA +1 -1
- {posthoganalytics-6.7.11.dist-info → posthoganalytics-6.7.13.dist-info}/RECORD +8 -8
- {posthoganalytics-6.7.11.dist-info → posthoganalytics-6.7.13.dist-info}/WHEEL +0 -0
- {posthoganalytics-6.7.11.dist-info → posthoganalytics-6.7.13.dist-info}/licenses/LICENSE +0 -0
- {posthoganalytics-6.7.11.dist-info → posthoganalytics-6.7.13.dist-info}/top_level.txt +0 -0
|
@@ -20,8 +20,14 @@ from typing import (
|
|
|
20
20
|
)
|
|
21
21
|
from uuid import UUID
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
try:
|
|
24
|
+
# LangChain 1.0+ and modern 0.x with langchain-core
|
|
25
|
+
from langchain_core.callbacks.base import BaseCallbackHandler
|
|
26
|
+
from langchain_core.agents import AgentAction, AgentFinish
|
|
27
|
+
except (ImportError, ModuleNotFoundError):
|
|
28
|
+
# Fallback for older LangChain versions
|
|
29
|
+
from langchain.callbacks.base import BaseCallbackHandler
|
|
30
|
+
from langchain.schema.agent import AgentAction, AgentFinish
|
|
25
31
|
from langchain_core.documents import Document
|
|
26
32
|
from langchain_core.messages import (
|
|
27
33
|
AIMessage,
|
|
@@ -752,12 +758,19 @@ def _parse_usage_model(
|
|
|
752
758
|
"cache_read": "cache_read_tokens",
|
|
753
759
|
"reasoning": "reasoning_tokens",
|
|
754
760
|
}
|
|
755
|
-
|
|
761
|
+
normalized_usage = ModelUsage(
|
|
756
762
|
**{
|
|
757
763
|
dataclass_key: parsed_usage.get(mapped_key) or 0
|
|
758
764
|
for mapped_key, dataclass_key in field_mapping.items()
|
|
759
765
|
},
|
|
760
766
|
)
|
|
767
|
+
# In LangChain, input_tokens is the sum of input and cache read tokens.
|
|
768
|
+
# Our cost calculation expects them to be separate, for Anthropic.
|
|
769
|
+
if normalized_usage.input_tokens and normalized_usage.cache_read_tokens:
|
|
770
|
+
normalized_usage.input_tokens = max(
|
|
771
|
+
normalized_usage.input_tokens - normalized_usage.cache_read_tokens, 0
|
|
772
|
+
)
|
|
773
|
+
return normalized_usage
|
|
761
774
|
|
|
762
775
|
|
|
763
776
|
def _parse_usage(response: LLMResult) -> ModelUsage:
|
|
@@ -220,3 +220,32 @@ class PosthogContextMiddleware:
|
|
|
220
220
|
contexts.tag(k, v)
|
|
221
221
|
|
|
222
222
|
return await self.get_response(request)
|
|
223
|
+
|
|
224
|
+
def process_exception(self, request, exception):
|
|
225
|
+
# type: (HttpRequest, Exception) -> None
|
|
226
|
+
"""
|
|
227
|
+
Process exceptions from views and downstream middleware.
|
|
228
|
+
|
|
229
|
+
Django calls this WHILE still inside the context created by __call__,
|
|
230
|
+
so request tags have already been extracted and set. This method just
|
|
231
|
+
needs to capture the exception directly.
|
|
232
|
+
|
|
233
|
+
Django converts view exceptions into responses before they propagate through
|
|
234
|
+
the middleware stack, so the context manager in __call__/__acall__ never sees them.
|
|
235
|
+
|
|
236
|
+
Note: Django's process_exception is always synchronous, even for async views.
|
|
237
|
+
"""
|
|
238
|
+
if self.request_filter and not self.request_filter(request):
|
|
239
|
+
return
|
|
240
|
+
|
|
241
|
+
if not self.capture_exceptions:
|
|
242
|
+
return
|
|
243
|
+
|
|
244
|
+
# Context and tags already set by __call__ or __acall__
|
|
245
|
+
# Just capture the exception
|
|
246
|
+
if self.client:
|
|
247
|
+
self.client.capture_exception(exception)
|
|
248
|
+
else:
|
|
249
|
+
from posthoganalytics import capture_exception
|
|
250
|
+
|
|
251
|
+
capture_exception(exception)
|
posthoganalytics/version.py
CHANGED
|
@@ -11,7 +11,7 @@ posthoganalytics/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
11
11
|
posthoganalytics/request.py,sha256=Bsl2c5WwONKPQzwWMmKPX5VgOlwSiIcSNfhXgoz62Y8,6186
|
|
12
12
|
posthoganalytics/types.py,sha256=Dl3aFGX9XUR0wMmK12r2s5Hjan9jL4HpQ9GHpVcEq5U,10207
|
|
13
13
|
posthoganalytics/utils.py,sha256=-0w-OLcCaoldkbBebPzQyBzLJSo9G9yBOg8NDVz7La8,16088
|
|
14
|
-
posthoganalytics/version.py,sha256=
|
|
14
|
+
posthoganalytics/version.py,sha256=z7yZYOCp6BXEykkelq-f1lmR2VlKyCNAOJq990CeISk,88
|
|
15
15
|
posthoganalytics/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
posthoganalytics/ai/sanitization.py,sha256=owipZ4eJYtd4JTI-CM_klatclXaeaIec3XJBOUfsOnQ,5770
|
|
17
17
|
posthoganalytics/ai/types.py,sha256=ceubs4K9xf8vQx7wokq1NL9hPtxyS7D7sUOuT7Lx1lM,3237
|
|
@@ -25,14 +25,14 @@ posthoganalytics/ai/gemini/__init__.py,sha256=JV_9-gBR87leHgZW4XAYZP7LSl4YaXeuhq
|
|
|
25
25
|
posthoganalytics/ai/gemini/gemini.py,sha256=A2acjT_m8ru2YwgIk15aN21CRVEl2jh8pbqjmHplMC8,15035
|
|
26
26
|
posthoganalytics/ai/gemini/gemini_converter.py,sha256=WzRsid-FjXRyhAI5wQ9-tjTapYVCTRKuMPcZFYKUdIo,16027
|
|
27
27
|
posthoganalytics/ai/langchain/__init__.py,sha256=9CqAwLynTGj3ASAR80C3PmdTdrYGmu99tz0JL-HPFgI,70
|
|
28
|
-
posthoganalytics/ai/langchain/callbacks.py,sha256=
|
|
28
|
+
posthoganalytics/ai/langchain/callbacks.py,sha256=syDeSb4hOrwxjEtlmRodVhdgVAQi8iwg1Z63YHNUhvA,30297
|
|
29
29
|
posthoganalytics/ai/openai/__init__.py,sha256=u4OuUT7k1NgFj0TrxjuyegOg7a_UA8nAU6a-Hszr0OM,490
|
|
30
30
|
posthoganalytics/ai/openai/openai.py,sha256=I05NruE9grWezM_EgOZBiG5Ej_gABsDcYKN0pRQWvzU,20235
|
|
31
31
|
posthoganalytics/ai/openai/openai_async.py,sha256=YAaj8Q-X3bExx-BXLWUOtdTMdj3RKe8bUkTyjamNURo,21829
|
|
32
32
|
posthoganalytics/ai/openai/openai_converter.py,sha256=VBaAGdXPSVNgfvCnSAojslWkTRO2luUxpjafR-WMEbs,20469
|
|
33
33
|
posthoganalytics/ai/openai/openai_providers.py,sha256=RPVmj2V0_lAdno_ax5Ul2kwhBA9_rRgAdl_sCqrQc6M,4004
|
|
34
34
|
posthoganalytics/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
|
-
posthoganalytics/integrations/django.py,sha256=
|
|
35
|
+
posthoganalytics/integrations/django.py,sha256=4qXodtcvsbZ9Kujy05hn9_Rqftiz8mLyPRVTbCwUJ0U,9790
|
|
36
36
|
posthoganalytics/test/__init__.py,sha256=VYgM6xPbJbvS-xhIcDiBRs0MFC9V_jT65uNeerCz_rM,299
|
|
37
37
|
posthoganalytics/test/test_before_send.py,sha256=A1_UVMewhHAvO39rZDWfS606vG_X-q0KNXvh5DAKiB8,7930
|
|
38
38
|
posthoganalytics/test/test_client.py,sha256=e1dD9bFplZWROiP35fuyBDguGXC6ZmG5j79Iw2t_NBw,96363
|
|
@@ -47,8 +47,8 @@ posthoganalytics/test/test_request.py,sha256=Zc0VbkjpVmj8mKokQm9rzdgTr0b1U44vvMY
|
|
|
47
47
|
posthoganalytics/test/test_size_limited_dict.py,sha256=-5IQjIEr_-Dql24M0HusdR_XroOMrtgiT0v6ZQCRvzo,774
|
|
48
48
|
posthoganalytics/test/test_types.py,sha256=bRPHdwVpP7hu7emsplU8UVyzSQptv6PaG5lAoOD_BtM,7595
|
|
49
49
|
posthoganalytics/test/test_utils.py,sha256=sqUTbfweVcxxFRd3WDMFXqPMyU6DvzOBeAOc68Py9aw,9620
|
|
50
|
-
posthoganalytics-6.7.
|
|
51
|
-
posthoganalytics-6.7.
|
|
52
|
-
posthoganalytics-6.7.
|
|
53
|
-
posthoganalytics-6.7.
|
|
54
|
-
posthoganalytics-6.7.
|
|
50
|
+
posthoganalytics-6.7.13.dist-info/licenses/LICENSE,sha256=wGf9JBotDkSygFj43m49oiKlFnpMnn97keiZKF-40vE,2450
|
|
51
|
+
posthoganalytics-6.7.13.dist-info/METADATA,sha256=kno2ysdSn_QVgMzZE5DmGV8TXvNLL3jZvUZLWAjedIo,6025
|
|
52
|
+
posthoganalytics-6.7.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
53
|
+
posthoganalytics-6.7.13.dist-info/top_level.txt,sha256=8QsNIqIkBh1p2TXvKp0Em9ZLZKwe3uIqCETyW4s1GOE,17
|
|
54
|
+
posthoganalytics-6.7.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|