diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ceda0a8..f6f14f55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 7.8.1 - 2026-02-03 + +fix(llma): small fixes for prompt management + # 7.8.0 - 2026-01-28 feat(llma): add prompt management diff --git a/posthog/ai/prompts.py b/posthog/ai/prompts.py index aa6ca189..49f3213b 100644 --- a/posthog/ai/prompts.py +++ b/posthog/ai/prompts.py @@ -10,11 +10,12 @@ import urllib.parse from typing import Any, Dict, Optional, Union -from posthog.request import DEFAULT_HOST, USER_AGENT, _get_session +from posthog.request import USER_AGENT, _get_session from posthog.utils import remove_trailing_slash log = logging.getLogger("posthog") +APP_ENDPOINT = "https://app.posthog.com" DEFAULT_CACHE_TTL_SECONDS = 300 # 5 minutes PromptVariables = Dict[str, Union[str, int, float, bool]] @@ -49,11 +50,11 @@ class Prompts: from posthog.ai.prompts import Prompts # With PostHog client - posthog = Posthog('phc_xxx', host='https://us.i.posthog.com', personal_api_key='phx_xxx') + posthog = Posthog('phc_xxx', host='https://app.posthog.com', personal_api_key='phx_xxx') prompts = Prompts(posthog) # Or with direct options (no PostHog client needed) - prompts = Prompts(personal_api_key='phx_xxx', host='https://us.i.posthog.com') + prompts = Prompts(personal_api_key='phx_xxx', host='https://app.posthog.com') # Fetch with caching and fallback template = prompts.get('support-system-prompt', fallback='You are a helpful assistant.') @@ -80,7 +81,7 @@ def __init__( Args: posthog: PostHog client instance (optional if personal_api_key provided) personal_api_key: Direct API key (optional if posthog provided) - host: PostHog host (defaults to US ingestion endpoint) + host: PostHog host (defaults to app endpoint) default_cache_ttl_seconds: Default cache TTL (defaults to 300) """ self._default_cache_ttl_seconds = ( @@ -91,11 +92,11 @@ def __init__( if posthog is not None: self._personal_api_key = getattr(posthog, "personal_api_key", None) or "" self._host = remove_trailing_slash( - getattr(posthog, "raw_host", None) or DEFAULT_HOST + getattr(posthog, "raw_host", None) or APP_ENDPOINT ) else: self._personal_api_key = personal_api_key or "" - self._host = remove_trailing_slash(host or DEFAULT_HOST) + self._host = remove_trailing_slash(host or APP_ENDPOINT) def get( self, @@ -214,7 +215,7 @@ def _fetch_prompt_from_api(self, name: str) -> str: """ Fetch prompt from PostHog API. - Endpoint: {host}/api/projects/@current/llm_prompts/name/{encoded_name}/ + Endpoint: {host}/api/environments/@current/llm_prompts/name/{encoded_name}/ Auth: Bearer {personal_api_key} Args: @@ -233,7 +234,7 @@ def _fetch_prompt_from_api(self, name: str) -> str: ) encoded_name = urllib.parse.quote(name, safe="") - url = f"{self._host}/api/projects/@current/llm_prompts/name/{encoded_name}/" + url = f"{self._host}/api/environments/@current/llm_prompts/name/{encoded_name}/" headers = { "Authorization": f"Bearer {self._personal_api_key}", diff --git a/posthog/test/ai/test_prompts.py b/posthog/test/ai/test_prompts.py index 6f6cd18a..13821225 100644 --- a/posthog/test/ai/test_prompts.py +++ b/posthog/test/ai/test_prompts.py @@ -33,7 +33,7 @@ class TestPrompts(unittest.TestCase): } def create_mock_posthog( - self, personal_api_key="phx_test_key", host="https://us.i.posthog.com" + self, personal_api_key="phx_test_key", host="https://app.posthog.com" ): """Create a mock PostHog client.""" mock = MagicMock() @@ -61,7 +61,7 @@ def test_successfully_fetch_a_prompt(self, mock_get_session): call_args = mock_get.call_args self.assertEqual( call_args[0][0], - "https://us.i.posthog.com/api/projects/@current/llm_prompts/name/test-prompt/", + "https://app.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/", ) self.assertIn("Authorization", call_args[1]["headers"]) self.assertEqual( @@ -333,7 +333,7 @@ def test_url_encode_prompt_names_with_special_characters(self, mock_get_session) call_args = mock_get.call_args self.assertEqual( call_args[0][0], - "https://us.i.posthog.com/api/projects/@current/llm_prompts/name/prompt%20with%20spaces%2Fand%2Fslashes/", + "https://app.posthog.com/api/environments/@current/llm_prompts/name/prompt%20with%20spaces%2Fand%2Fslashes/", ) @patch("posthog.ai.prompts._get_session") @@ -350,7 +350,7 @@ def test_work_with_direct_options_no_posthog_client(self, mock_get_session): call_args = mock_get.call_args self.assertEqual( call_args[0][0], - "https://us.i.posthog.com/api/projects/@current/llm_prompts/name/test-prompt/", + "https://app.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/", ) self.assertEqual( call_args[1]["headers"]["Authorization"], "Bearer phx_direct_key" @@ -363,7 +363,7 @@ def test_use_custom_host_from_direct_options(self, mock_get_session): mock_get.return_value = MockResponse(json_data=self.mock_prompt_response) prompts = Prompts( - personal_api_key="phx_direct_key", host="https://eu.i.posthog.com" + personal_api_key="phx_direct_key", host="https://eu.posthog.com" ) prompts.get("test-prompt") @@ -371,7 +371,7 @@ def test_use_custom_host_from_direct_options(self, mock_get_session): call_args = mock_get.call_args self.assertEqual( call_args[0][0], - "https://eu.i.posthog.com/api/projects/@current/llm_prompts/name/test-prompt/", + "https://eu.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/", ) @patch("posthog.ai.prompts._get_session") diff --git a/posthog/version.py b/posthog/version.py index 292b335f..db5d0690 100644 --- a/posthog/version.py +++ b/posthog/version.py @@ -1,4 +1,4 @@ -VERSION = "7.8.0" +VERSION = "7.8.1" if __name__ == "__main__": print(VERSION, end="") # noqa: T201