Skip to content

Commit d4f2d6d

Browse files
authored
fix(llma): small fixes for prompt management (#420)
* fix(llma): small fixes for prompt management * fix(llma): tests * fix(llma): tests
1 parent 72f4488 commit d4f2d6d

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 7.8.1 - 2026-02-03
2+
3+
fix(llma): small fixes for prompt management
4+
15
# 7.8.0 - 2026-01-28
26

37
feat(llma): add prompt management

posthog/ai/prompts.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
import urllib.parse
1111
from typing import Any, Dict, Optional, Union
1212

13-
from posthog.request import DEFAULT_HOST, USER_AGENT, _get_session
13+
from posthog.request import USER_AGENT, _get_session
1414
from posthog.utils import remove_trailing_slash
1515

1616
log = logging.getLogger("posthog")
1717

18+
APP_ENDPOINT = "https://app.posthog.com"
1819
DEFAULT_CACHE_TTL_SECONDS = 300 # 5 minutes
1920

2021
PromptVariables = Dict[str, Union[str, int, float, bool]]
@@ -49,11 +50,11 @@ class Prompts:
4950
from posthog.ai.prompts import Prompts
5051
5152
# With PostHog client
52-
posthog = Posthog('phc_xxx', host='https://us.i.posthog.com', personal_api_key='phx_xxx')
53+
posthog = Posthog('phc_xxx', host='https://app.posthog.com', personal_api_key='phx_xxx')
5354
prompts = Prompts(posthog)
5455
5556
# Or with direct options (no PostHog client needed)
56-
prompts = Prompts(personal_api_key='phx_xxx', host='https://us.i.posthog.com')
57+
prompts = Prompts(personal_api_key='phx_xxx', host='https://app.posthog.com')
5758
5859
# Fetch with caching and fallback
5960
template = prompts.get('support-system-prompt', fallback='You are a helpful assistant.')
@@ -80,7 +81,7 @@ def __init__(
8081
Args:
8182
posthog: PostHog client instance (optional if personal_api_key provided)
8283
personal_api_key: Direct API key (optional if posthog provided)
83-
host: PostHog host (defaults to US ingestion endpoint)
84+
host: PostHog host (defaults to app endpoint)
8485
default_cache_ttl_seconds: Default cache TTL (defaults to 300)
8586
"""
8687
self._default_cache_ttl_seconds = (
@@ -91,11 +92,11 @@ def __init__(
9192
if posthog is not None:
9293
self._personal_api_key = getattr(posthog, "personal_api_key", None) or ""
9394
self._host = remove_trailing_slash(
94-
getattr(posthog, "raw_host", None) or DEFAULT_HOST
95+
getattr(posthog, "raw_host", None) or APP_ENDPOINT
9596
)
9697
else:
9798
self._personal_api_key = personal_api_key or ""
98-
self._host = remove_trailing_slash(host or DEFAULT_HOST)
99+
self._host = remove_trailing_slash(host or APP_ENDPOINT)
99100

100101
def get(
101102
self,
@@ -214,7 +215,7 @@ def _fetch_prompt_from_api(self, name: str) -> str:
214215
"""
215216
Fetch prompt from PostHog API.
216217
217-
Endpoint: {host}/api/projects/@current/llm_prompts/name/{encoded_name}/
218+
Endpoint: {host}/api/environments/@current/llm_prompts/name/{encoded_name}/
218219
Auth: Bearer {personal_api_key}
219220
220221
Args:
@@ -233,7 +234,7 @@ def _fetch_prompt_from_api(self, name: str) -> str:
233234
)
234235

235236
encoded_name = urllib.parse.quote(name, safe="")
236-
url = f"{self._host}/api/projects/@current/llm_prompts/name/{encoded_name}/"
237+
url = f"{self._host}/api/environments/@current/llm_prompts/name/{encoded_name}/"
237238

238239
headers = {
239240
"Authorization": f"Bearer {self._personal_api_key}",

posthog/test/ai/test_prompts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestPrompts(unittest.TestCase):
3333
}
3434

3535
def create_mock_posthog(
36-
self, personal_api_key="phx_test_key", host="https://us.i.posthog.com"
36+
self, personal_api_key="phx_test_key", host="https://app.posthog.com"
3737
):
3838
"""Create a mock PostHog client."""
3939
mock = MagicMock()
@@ -61,7 +61,7 @@ def test_successfully_fetch_a_prompt(self, mock_get_session):
6161
call_args = mock_get.call_args
6262
self.assertEqual(
6363
call_args[0][0],
64-
"https://us.i.posthog.com/api/projects/@current/llm_prompts/name/test-prompt/",
64+
"https://app.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/",
6565
)
6666
self.assertIn("Authorization", call_args[1]["headers"])
6767
self.assertEqual(
@@ -333,7 +333,7 @@ def test_url_encode_prompt_names_with_special_characters(self, mock_get_session)
333333
call_args = mock_get.call_args
334334
self.assertEqual(
335335
call_args[0][0],
336-
"https://us.i.posthog.com/api/projects/@current/llm_prompts/name/prompt%20with%20spaces%2Fand%2Fslashes/",
336+
"https://app.posthog.com/api/environments/@current/llm_prompts/name/prompt%20with%20spaces%2Fand%2Fslashes/",
337337
)
338338

339339
@patch("posthog.ai.prompts._get_session")
@@ -350,7 +350,7 @@ def test_work_with_direct_options_no_posthog_client(self, mock_get_session):
350350
call_args = mock_get.call_args
351351
self.assertEqual(
352352
call_args[0][0],
353-
"https://us.i.posthog.com/api/projects/@current/llm_prompts/name/test-prompt/",
353+
"https://app.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/",
354354
)
355355
self.assertEqual(
356356
call_args[1]["headers"]["Authorization"], "Bearer phx_direct_key"
@@ -363,15 +363,15 @@ def test_use_custom_host_from_direct_options(self, mock_get_session):
363363
mock_get.return_value = MockResponse(json_data=self.mock_prompt_response)
364364

365365
prompts = Prompts(
366-
personal_api_key="phx_direct_key", host="https://eu.i.posthog.com"
366+
personal_api_key="phx_direct_key", host="https://eu.posthog.com"
367367
)
368368

369369
prompts.get("test-prompt")
370370

371371
call_args = mock_get.call_args
372372
self.assertEqual(
373373
call_args[0][0],
374-
"https://eu.i.posthog.com/api/projects/@current/llm_prompts/name/test-prompt/",
374+
"https://eu.posthog.com/api/environments/@current/llm_prompts/name/test-prompt/",
375375
)
376376

377377
@patch("posthog.ai.prompts._get_session")

posthog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "7.8.0"
1+
VERSION = "7.8.1"
22

33
if __name__ == "__main__":
44
print(VERSION, end="") # noqa: T201

0 commit comments

Comments
 (0)