diff --git a/ee/hogai/eval/tests/test_eval_funnel_generator.py b/ee/hogai/eval/tests/test_eval_funnel_generator.py index e032697df00e6..cd7e93b260ae9 100644 --- a/ee/hogai/eval/tests/test_eval_funnel_generator.py +++ b/ee/hogai/eval/tests/test_eval_funnel_generator.py @@ -1,14 +1,13 @@ from langgraph.graph.state import CompiledStateGraph -from pydantic import BaseModel from ee.hogai.assistant import AssistantGraph from ee.hogai.eval.utils import EvalBaseTest from ee.hogai.utils import AssistantNodeName -from posthog.schema import HumanMessage +from posthog.schema import AssistantFunnelsQuery, HumanMessage class TestEvalFunnelGenerator(EvalBaseTest): - def _call_node(self, query: str, plan: str) -> BaseModel: + def _call_node(self, query: str, plan: str) -> AssistantFunnelsQuery: graph: CompiledStateGraph = ( AssistantGraph(self.team) .add_edge(AssistantNodeName.START, AssistantNodeName.FUNNEL_GENERATOR) diff --git a/ee/hogai/eval/tests/test_eval_trends_generator.py b/ee/hogai/eval/tests/test_eval_trends_generator.py index 28fcad1cd1d9b..c5341584ca2f7 100644 --- a/ee/hogai/eval/tests/test_eval_trends_generator.py +++ b/ee/hogai/eval/tests/test_eval_trends_generator.py @@ -1,14 +1,13 @@ from langgraph.graph.state import CompiledStateGraph -from pydantic import BaseModel from ee.hogai.assistant import AssistantGraph from ee.hogai.eval.utils import EvalBaseTest from ee.hogai.utils import AssistantNodeName -from posthog.schema import HumanMessage +from posthog.schema import AssistantTrendsQuery, HumanMessage class TestEvalTrendsGenerator(EvalBaseTest): - def _call_node(self, query: str, plan: str) -> BaseModel: + def _call_node(self, query: str, plan: str) -> AssistantTrendsQuery: graph: CompiledStateGraph = ( AssistantGraph(self.team) .add_edge(AssistantNodeName.START, AssistantNodeName.TRENDS_GENERATOR) @@ -34,3 +33,21 @@ def test_node_replaces_equals_with_contains(self): assert "icontains" in actual_output assert "John" not in actual_output assert "john" in actual_output + + def test_node_leans_towards_line_graph(self): + query = "How often do users download files?" + # We ideally want to consider both total count of downloads per period, as well as how often a median user downloads + plan = """Events: + - downloaded_file + - math operation: total count + - downloaded_file + - math operation: median count per user + """ + actual_output = self._call_node(query, plan) + assert actual_output.trendsFilter.display == "ActionsLineGraph" + assert actual_output.series[0].kind == "EventsNode" + assert actual_output.series[0].event == "downloaded_file" + assert actual_output.series[0].math == "total" + assert actual_output.series[1].kind == "EventsNode" + assert actual_output.series[1].event == "downloaded_file" + assert actual_output.series[1].math == "median_count_per_actor" diff --git a/ee/hogai/trends/prompts.py b/ee/hogai/trends/prompts.py index 01c9751769b00..2ac9496480cdd 100644 --- a/ee/hogai/trends/prompts.py +++ b/ee/hogai/trends/prompts.py @@ -52,7 +52,7 @@ - 95th percentile - 99th percentile -Available math aggregation types counting by users who completed an event are: +Available math aggregation types counting number of events completed per user (intensity of usage) are: - average - minimum - maximum diff --git a/ee/hogai/trends/toolkit.py b/ee/hogai/trends/toolkit.py index 672f065a1f217..d69830d2f2cd6 100644 --- a/ee/hogai/trends/toolkit.py +++ b/ee/hogai/trends/toolkit.py @@ -61,7 +61,7 @@ def generate_trends_schema() -> dict: schema = AssistantTrendsQuery.model_json_schema() return { "name": "output_insight_schema", - "description": "Outputs the JSON schema of a funnel insight", + "description": "Outputs the JSON schema of a trends insight", "parameters": { "type": "object", "properties": { diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json index 50d70878c64bc..a83a40dad42a1 100644 --- a/frontend/src/queries/schema.json +++ b/frontend/src/queries/schema.json @@ -1304,7 +1304,7 @@ }, "display": { "default": "ActionsLineGraph", - "description": "Changes the visualization type. `ActionsLineGraph` - if the user wants to see dynamics in time like a line graph. Prefer this option. `ActionsLineGraphCumulative` - if the user wants to see cumulative dynamics across time. `ActionsBarValue` - if the data is categorical and needs to be visualized as a bar chart. `ActionsBar` - if the data is categorical and can be visualized as a stacked bar chart. `ActionsPie` - if the data is easy to understand in a pie chart. `BoldNumber` - if the user asks a question where you can answer with a single number. You can't use this option with breakdowns. `ActionsTable` - if the user wants to see a table. `ActionsAreaGraph` - if the data is better visualized in an area graph. `WorldMap` - if the user has only one series and wants to see data from particular countries. It can only be used with the `$geoip_country_name` breakdown.", + "description": "Visualization type. Available values: `ActionsLineGraph` - time-series line chart; most common option, as it shows change over time. `ActionsBar` - time-series bar chart. `ActionsAreaGraph` - time-series area chart. `ActionsLineGraphCumulative` - cumulative time-series line chart; good for cumulative metrics. `BoldNumber` - total value single large number. You can't use this with breakdown; use when user explicitly asks for a single output number. `ActionsBarValue` - total value (NOT time-series) bar chart; good for categorical data. `ActionsPie` - total value pie chart; good for visualizing proportions. `ActionsTable` - total value table; good when using breakdown to list users or other entities. `WorldMap` - total value world map; use when breaking down by country name using property `$geoip_country_name`, and only then.", "enum": [ "ActionsLineGraph", "ActionsBar", diff --git a/frontend/src/queries/schema.ts b/frontend/src/queries/schema.ts index ae5d085a349c4..5f106dfab26c8 100644 --- a/frontend/src/queries/schema.ts +++ b/frontend/src/queries/schema.ts @@ -1098,16 +1098,16 @@ export interface AssistantTrendsFilter { formula?: TrendsFilterLegacy['formula'] /** - * Changes the visualization type. - * `ActionsLineGraph` - if the user wants to see dynamics in time like a line graph. Prefer this option. - * `ActionsLineGraphCumulative` - if the user wants to see cumulative dynamics across time. - * `ActionsBarValue` - if the data is categorical and needs to be visualized as a bar chart. - * `ActionsBar` - if the data is categorical and can be visualized as a stacked bar chart. - * `ActionsPie` - if the data is easy to understand in a pie chart. - * `BoldNumber` - if the user asks a question where you can answer with a single number. You can't use this option with breakdowns. - * `ActionsTable` - if the user wants to see a table. - * `ActionsAreaGraph` - if the data is better visualized in an area graph. - * `WorldMap` - if the user has only one series and wants to see data from particular countries. It can only be used with the `$geoip_country_name` breakdown. + * Visualization type. Available values: + * `ActionsLineGraph` - time-series line chart; most common option, as it shows change over time. + * `ActionsBar` - time-series bar chart. + * `ActionsAreaGraph` - time-series area chart. + * `ActionsLineGraphCumulative` - cumulative time-series line chart; good for cumulative metrics. + * `BoldNumber` - total value single large number. You can't use this with breakdown; use when user explicitly asks for a single output number. + * `ActionsBarValue` - total value (NOT time-series) bar chart; good for categorical data. + * `ActionsPie` - total value pie chart; good for visualizing proportions. + * `ActionsTable` - total value table; good when using breakdown to list users or other entities. + * `WorldMap` - total value world map; use when breaking down by country name using property `$geoip_country_name`, and only then. * @default ActionsLineGraph */ display?: AssistantTrendsDisplayType diff --git a/posthog/schema.py b/posthog/schema.py index 1b9ba09ef7b01..93b010344e9bd 100644 --- a/posthog/schema.py +++ b/posthog/schema.py @@ -353,15 +353,15 @@ class AssistantTrendsFilter(BaseModel): display: Optional[Display] = Field( default=Display.ACTIONS_LINE_GRAPH, description=( - "Changes the visualization type. `ActionsLineGraph` - if the user wants to see dynamics in time like a line" - " graph. Prefer this option. `ActionsLineGraphCumulative` - if the user wants to see cumulative dynamics" - " across time. `ActionsBarValue` - if the data is categorical and needs to be visualized as a bar chart." - " `ActionsBar` - if the data is categorical and can be visualized as a stacked bar chart. `ActionsPie` - if" - " the data is easy to understand in a pie chart. `BoldNumber` - if the user asks a question where you can" - " answer with a single number. You can't use this option with breakdowns. `ActionsTable` - if the user" - " wants to see a table. `ActionsAreaGraph` - if the data is better visualized in an area graph. `WorldMap`" - " - if the user has only one series and wants to see data from particular countries. It can only be used" - " with the `$geoip_country_name` breakdown." + "Visualization type. Available values: `ActionsLineGraph` - time-series line chart; most common option, as" + " it shows change over time. `ActionsBar` - time-series bar chart. `ActionsAreaGraph` - time-series area" + " chart. `ActionsLineGraphCumulative` - cumulative time-series line chart; good for cumulative metrics." + " `BoldNumber` - total value single large number. You can't use this with breakdown; use when user" + " explicitly asks for a single output number. `ActionsBarValue` - total value (NOT time-series) bar chart;" + " good for categorical data. `ActionsPie` - total value pie chart; good for visualizing proportions." + " `ActionsTable` - total value table; good when using breakdown to list users or other entities. `WorldMap`" + " - total value world map; use when breaking down by country name using property `$geoip_country_name`, and" + " only then." ), ) formula: Optional[str] = Field(default=None, description="If the formula is provided, apply it here.")