posthoganalytics 7.8.0__tar.gz → 7.8.1__tar.gz
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-7.8.0/posthoganalytics.egg-info → posthoganalytics-7.8.1}/PKG-INFO +1 -1
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/prompts.py +9 -8
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/test_prompts.py +6 -6
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/version.py +1 -1
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1/posthoganalytics.egg-info}/PKG-INFO +1 -1
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/LICENSE +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/MANIFEST.in +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/README.md +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/anthropic/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/anthropic/anthropic.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/anthropic/anthropic_async.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/anthropic/anthropic_converter.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/anthropic/anthropic_providers.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/gemini/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/gemini/gemini.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/gemini/gemini_async.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/gemini/gemini_converter.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/langchain/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/langchain/callbacks.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/openai.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/openai_async.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/openai_converter.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/openai_providers.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai_agents/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai_agents/processor.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/sanitization.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/types.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/utils.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/args.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/client.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/consumer.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/contexts.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/exception_capture.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/exception_utils.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/feature_flags.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/flag_definition_cache.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/integrations/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/integrations/django.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/poller.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/py.typed +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/request.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/openai_agents/__init__.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/openai_agents/test_processor.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/test_sanitization.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/test_system_prompts.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_before_send.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_client.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_consumer.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_contexts.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_exception_capture.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_feature_flag.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_feature_flag_result.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_feature_flags.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_flag_definition_cache.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_module.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_request.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_size_limited_dict.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_types.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_utils.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/types.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/utils.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics.egg-info/SOURCES.txt +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics.egg-info/dependency_links.txt +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics.egg-info/requires.txt +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics.egg-info/top_level.txt +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/pyproject.toml +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/setup.cfg +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/setup.py +0 -0
- {posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/setup_analytics.py +0 -0
|
@@ -10,11 +10,12 @@ import time
|
|
|
10
10
|
import urllib.parse
|
|
11
11
|
from typing import Any, Dict, Optional, Union
|
|
12
12
|
|
|
13
|
-
from posthoganalytics.request import
|
|
13
|
+
from posthoganalytics.request import USER_AGENT, _get_session
|
|
14
14
|
from posthoganalytics.utils import remove_trailing_slash
|
|
15
15
|
|
|
16
16
|
log = logging.getLogger("posthog")
|
|
17
17
|
|
|
18
|
+
APP_ENDPOINT = "https://app.posthog.com"
|
|
18
19
|
DEFAULT_CACHE_TTL_SECONDS = 300 # 5 minutes
|
|
19
20
|
|
|
20
21
|
PromptVariables = Dict[str, Union[str, int, float, bool]]
|
|
@@ -49,11 +50,11 @@ class Prompts:
|
|
|
49
50
|
from posthoganalytics.ai.prompts import Prompts
|
|
50
51
|
|
|
51
52
|
# With PostHog client
|
|
52
|
-
posthog = Posthog('phc_xxx', host='https://
|
|
53
|
+
posthog = Posthog('phc_xxx', host='https://app.posthog.com', personal_api_key='phx_xxx')
|
|
53
54
|
prompts = Prompts(posthog)
|
|
54
55
|
|
|
55
56
|
# Or with direct options (no PostHog client needed)
|
|
56
|
-
prompts = Prompts(personal_api_key='phx_xxx', host='https://
|
|
57
|
+
prompts = Prompts(personal_api_key='phx_xxx', host='https://app.posthog.com')
|
|
57
58
|
|
|
58
59
|
# Fetch with caching and fallback
|
|
59
60
|
template = prompts.get('support-system-prompt', fallback='You are a helpful assistant.')
|
|
@@ -80,7 +81,7 @@ class Prompts:
|
|
|
80
81
|
Args:
|
|
81
82
|
posthog: PostHog client instance (optional if personal_api_key provided)
|
|
82
83
|
personal_api_key: Direct API key (optional if posthog provided)
|
|
83
|
-
host: PostHog host (defaults to
|
|
84
|
+
host: PostHog host (defaults to app endpoint)
|
|
84
85
|
default_cache_ttl_seconds: Default cache TTL (defaults to 300)
|
|
85
86
|
"""
|
|
86
87
|
self._default_cache_ttl_seconds = (
|
|
@@ -91,11 +92,11 @@ class Prompts:
|
|
|
91
92
|
if posthog is not None:
|
|
92
93
|
self._personal_api_key = getattr(posthog, "personal_api_key", None) or ""
|
|
93
94
|
self._host = remove_trailing_slash(
|
|
94
|
-
getattr(posthog, "raw_host", None) or
|
|
95
|
+
getattr(posthog, "raw_host", None) or APP_ENDPOINT
|
|
95
96
|
)
|
|
96
97
|
else:
|
|
97
98
|
self._personal_api_key = personal_api_key or ""
|
|
98
|
-
self._host = remove_trailing_slash(host or
|
|
99
|
+
self._host = remove_trailing_slash(host or APP_ENDPOINT)
|
|
99
100
|
|
|
100
101
|
def get(
|
|
101
102
|
self,
|
|
@@ -214,7 +215,7 @@ class Prompts:
|
|
|
214
215
|
"""
|
|
215
216
|
Fetch prompt from PostHog API.
|
|
216
217
|
|
|
217
|
-
Endpoint: {host}/api/
|
|
218
|
+
Endpoint: {host}/api/environments/@current/llm_prompts/name/{encoded_name}/
|
|
218
219
|
Auth: Bearer {personal_api_key}
|
|
219
220
|
|
|
220
221
|
Args:
|
|
@@ -233,7 +234,7 @@ class Prompts:
|
|
|
233
234
|
)
|
|
234
235
|
|
|
235
236
|
encoded_name = urllib.parse.quote(name, safe="")
|
|
236
|
-
url = f"{self._host}/api/
|
|
237
|
+
url = f"{self._host}/api/environments/@current/llm_prompts/name/{encoded_name}/"
|
|
237
238
|
|
|
238
239
|
headers = {
|
|
239
240
|
"Authorization": f"Bearer {self._personal_api_key}",
|
|
@@ -33,7 +33,7 @@ class TestPrompts(unittest.TestCase):
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
def create_mock_posthog(
|
|
36
|
-
self, personal_api_key="phx_test_key", host="https://
|
|
36
|
+
self, personal_api_key="phx_test_key", host="https://app.posthog.com"
|
|
37
37
|
):
|
|
38
38
|
"""Create a mock PostHog client."""
|
|
39
39
|
mock = MagicMock()
|
|
@@ -61,7 +61,7 @@ class TestPromptsGet(TestPrompts):
|
|
|
61
61
|
call_args = mock_get.call_args
|
|
62
62
|
self.assertEqual(
|
|
63
63
|
call_args[0][0],
|
|
64
|
-
"https://
|
|
64
|
+
"https://app.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/",
|
|
65
65
|
)
|
|
66
66
|
self.assertIn("Authorization", call_args[1]["headers"])
|
|
67
67
|
self.assertEqual(
|
|
@@ -333,7 +333,7 @@ class TestPromptsGet(TestPrompts):
|
|
|
333
333
|
call_args = mock_get.call_args
|
|
334
334
|
self.assertEqual(
|
|
335
335
|
call_args[0][0],
|
|
336
|
-
"https://
|
|
336
|
+
"https://app.posthog.com/api/environments/@current/llm_prompts/name/prompt%20with%20spaces%2Fand%2Fslashes/",
|
|
337
337
|
)
|
|
338
338
|
|
|
339
339
|
@patch("posthog.ai.prompts._get_session")
|
|
@@ -350,7 +350,7 @@ class TestPromptsGet(TestPrompts):
|
|
|
350
350
|
call_args = mock_get.call_args
|
|
351
351
|
self.assertEqual(
|
|
352
352
|
call_args[0][0],
|
|
353
|
-
"https://
|
|
353
|
+
"https://app.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/",
|
|
354
354
|
)
|
|
355
355
|
self.assertEqual(
|
|
356
356
|
call_args[1]["headers"]["Authorization"], "Bearer phx_direct_key"
|
|
@@ -363,7 +363,7 @@ class TestPromptsGet(TestPrompts):
|
|
|
363
363
|
mock_get.return_value = MockResponse(json_data=self.mock_prompt_response)
|
|
364
364
|
|
|
365
365
|
prompts = Prompts(
|
|
366
|
-
personal_api_key="phx_direct_key", host="https://eu.
|
|
366
|
+
personal_api_key="phx_direct_key", host="https://eu.posthog.com"
|
|
367
367
|
)
|
|
368
368
|
|
|
369
369
|
prompts.get("test-prompt")
|
|
@@ -371,7 +371,7 @@ class TestPromptsGet(TestPrompts):
|
|
|
371
371
|
call_args = mock_get.call_args
|
|
372
372
|
self.assertEqual(
|
|
373
373
|
call_args[0][0],
|
|
374
|
-
"https://eu.
|
|
374
|
+
"https://eu.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/",
|
|
375
375
|
)
|
|
376
376
|
|
|
377
377
|
@patch("posthog.ai.prompts._get_session")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/anthropic/anthropic.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/anthropic/anthropic_async.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/gemini/gemini_async.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/gemini/gemini_converter.py
RENAMED
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/langchain/callbacks.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/openai_async.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/openai_converter.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai/openai_providers.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai_agents/__init__.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/ai/openai_agents/processor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/openai_agents/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/test_sanitization.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/ai/test_system_prompts.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_exception_capture.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_feature_flag.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_feature_flag_result.py
RENAMED
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_feature_flags.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics/test/test_size_limited_dict.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-7.8.0 → posthoganalytics-7.8.1}/posthoganalytics.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|