Skip to content

Commit

Permalink
fix(product-assistant): filter out low frequency events (#25827)
Browse files Browse the repository at this point in the history
  • Loading branch information
skoob13 authored Oct 25, 2024
1 parent 544e239 commit db1e4ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 5 additions & 1 deletion ee/hogai/trends/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def _events_prompt(self) -> str:
if not isinstance(response, CachedTeamTaxonomyQueryResponse):
raise ValueError("Failed to generate events prompt.")

events = [item.event for item in response.results]
events: list[str] = []
for item in response.results:
if len(response.results) > 25 and item.count <= 3:
continue
events.append(item.event)

# default for null in the
tags: list[str] = ["all events"]
Expand Down
24 changes: 20 additions & 4 deletions ee/hogai/trends/test/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

from ee.hogai.trends.nodes import CreateTrendsPlanNode, GenerateTrendsNode
from posthog.schema import AssistantMessage, ExperimentalAITrendsQuery, HumanMessage, VisualizationMessage
from posthog.test.base import (
APIBaseTest,
ClickhouseTestMixin,
)
from posthog.test.base import APIBaseTest, ClickhouseTestMixin, _create_event, _create_person


@override_settings(IN_UNIT_TESTING=True)
class TestPlanAgentNode(ClickhouseTestMixin, APIBaseTest):
def setUp(self):
super().setUp()
self.schema = ExperimentalAITrendsQuery(series=[])

def test_agent_reconstructs_conversation(self):
Expand Down Expand Up @@ -70,6 +68,24 @@ def test_agent_reconstructs_conversation_and_omits_unknown_messages(self):
self.assertIn("Text", history[0].content)
self.assertNotIn("{{question}}", history[0].content)

def test_agent_filters_out_low_count_events(self):
_create_person(distinct_ids=["test"], team=self.team)
for i in range(26):
_create_event(event=f"event{i}", distinct_id="test", team=self.team)
_create_event(event="distinctevent", distinct_id="test", team=self.team)
node = CreateTrendsPlanNode(self.team)
self.assertEqual(
node._events_prompt,
"<list of available events for filtering>\nall events\ndistinctevent\n</list of available events for filtering>",
)

def test_agent_preserves_low_count_events_for_smaller_teams(self):
_create_person(distinct_ids=["test"], team=self.team)
_create_event(event="distinctevent", distinct_id="test", team=self.team)
node = CreateTrendsPlanNode(self.team)
self.assertIn("distinctevent", node._events_prompt)
self.assertIn("all events", node._events_prompt)


@override_settings(IN_UNIT_TESTING=True)
class TestGenerateTrendsNode(ClickhouseTestMixin, APIBaseTest):
Expand Down

0 comments on commit db1e4ad

Please sign in to comment.