Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(product-assistant): improve generation prompts #25862

Merged
merged 23 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2c495a6
fix: exclude cohorts and actions
skoob13 Oct 28, 2024
7d94895
fix: remove actions
skoob13 Oct 28, 2024
a79fca8
fix: return descriptive messages when there are no values
skoob13 Oct 28, 2024
703b546
chore: simplify the trends prompt
skoob13 Oct 29, 2024
a2fd30f
fix: remove plans from prompt
skoob13 Oct 29, 2024
80f80b5
Merge branch 'master' of github.com:PostHog/posthog into fix/prompt-t…
skoob13 Oct 30, 2024
33981dc
fix: question prompt follows the react prompt
skoob13 Oct 30, 2024
1bd63a7
fix: add the role
skoob13 Oct 30, 2024
c84671c
Merge branch 'master' of github.com:PostHog/posthog into fix/prompt-t…
skoob13 Oct 30, 2024
0b47797
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 30, 2024
e202b79
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 30, 2024
063021a
Merge branch 'master' of github.com:PostHog/posthog into fix/prompt-t…
skoob13 Oct 31, 2024
a22751c
Merge branch 'fix/prompt-tweaks' of github.com:PostHog/posthog into f…
skoob13 Oct 31, 2024
a2a6cc1
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 31, 2024
d2452bd
feat: slightly tweak the agent prompt
skoob13 Oct 31, 2024
9c6720a
Merge branch 'fix/prompt-tweaks' of github.com:PostHog/posthog into f…
skoob13 Oct 31, 2024
68f6862
Merge branch 'master' into fix/prompt-tweaks
skoob13 Oct 31, 2024
75b4662
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 31, 2024
24de9dd
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 31, 2024
c36f812
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 31, 2024
d87c061
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 31, 2024
c29d608
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 31, 2024
5860215
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 59 additions & 51 deletions ee/hogai/trends/prompts.py

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions ee/hogai/trends/test/test_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ def test_retrieve_entity_properties(self):
toolkit.retrieve_entity_properties("session"),
)

def test_retrieve_entity_properties_returns_descriptive_feedback_without_properties(self):
toolkit = TrendsAgentToolkit(self.team)
self.assertEqual(
toolkit.retrieve_entity_properties("person"),
"Properties do not exist in the taxonomy for the entity person.",
)

def test_retrieve_entity_property_values(self):
toolkit = TrendsAgentToolkit(self.team)
self.assertEqual(
Expand Down Expand Up @@ -173,6 +180,13 @@ def test_group_names(self):
toolkit = TrendsAgentToolkit(self.team)
self.assertEqual(toolkit._entity_names, ["person", "session", "proj", "org"])

def test_retrieve_event_properties_returns_descriptive_feedback_without_properties(self):
toolkit = TrendsAgentToolkit(self.team)
self.assertEqual(
toolkit.retrieve_event_properties("pageview"),
"Properties do not exist in the taxonomy for the event pageview.",
)

def test_empty_events(self):
toolkit = TrendsAgentToolkit(self.team)
self.assertEqual(
Expand Down
24 changes: 15 additions & 9 deletions ee/hogai/trends/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def tools(self) -> list[ToolkitTool]:
```
Args:
final_response: List all events, actions, and properties that you want to use to answer the question.
final_response: List all events and properties that you want to use to answer the question.
""",
},
]
Expand Down Expand Up @@ -285,6 +285,9 @@ def retrieve_entity_properties(self, entity: str) -> str:
).values_list("name", "property_type")
props = list(qs)

if not props:
return f"Properties do not exist in the taxonomy for the entity {entity}."

return self._generate_properties_xml(props)

def retrieve_event_properties(self, event_name: str) -> str:
Expand All @@ -305,15 +308,17 @@ def retrieve_event_properties(self, event_name: str) -> str:
team=self._team, type=PropertyDefinition.Type.EVENT, name__in=[item.property for item in response.results]
)
property_to_type = {property_definition.name: property_definition.property_type for property_definition in qs}
props = [
(item.property, property_to_type.get(item.property))
for item in response.results
# Exclude properties that exist in the taxonomy, but don't have a type.
if item.property in property_to_type
]

return self._generate_properties_xml(
[
(item.property, property_to_type.get(item.property))
for item in response.results
# Exclude properties that exist in the taxonomy, but don't have a type.
if item.property in property_to_type
]
)
if not props:
return f"Properties do not exist in the taxonomy for the event {event_name}."

return self._generate_properties_xml(props)

def _format_property_values(
self, sample_values: list, sample_count: Optional[int] = 0, format_as_string: bool = False
Expand Down Expand Up @@ -475,6 +480,7 @@ def _flatten_schema(self):
"PersonPropertyFilter",
"SessionPropertyFilter",
"FeaturePropertyFilter",
"GroupPropertyFilter",
)

# Clean up the property filters
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 1 addition & 64 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"AIActionsNode": {
"additionalProperties": false,
"properties": {
"custom_name": {
"type": "string"
},
"event": {
"description": "The event or `null` for all events.",
"type": ["string", "null"]
},
"fixedProperties": {
"items": {
"$ref": "#/definitions/AIPropertyFilter"
},
"type": "array"
},
"kind": {
"const": "EventsNode",
"type": "string"
},
"math": {
"$ref": "#/definitions/MathType"
},
"math_group_type_index": {
"enum": [0, 1, 2, 3, 4],
"type": "number"
},
"math_property": {
"type": "string"
},
"math_property_type": {
"type": "string"
},
"name": {
"type": "string"
},
"orderBy": {
"description": "Columns to order by",
"items": {
"type": "string"
},
"type": "array"
},
"properties": {
"items": {
"$ref": "#/definitions/AIPropertyFilter"
},
"type": "array"
},
"response": {
"type": "object"
}
},
"required": ["kind"],
"type": "object"
},
"AIEventsNode": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -5536,14 +5480,7 @@
"series": {
"description": "Events and actions to include",
"items": {
"anyOf": [
{
"$ref": "#/definitions/AIEventsNode"
},
{
"$ref": "#/definitions/AIActionsNode"
}
]
"$ref": "#/definitions/AIEventsNode"
},
"type": "array"
},
Expand Down
8 changes: 1 addition & 7 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,6 @@ export interface AIEventsNode
fixedProperties?: AIPropertyFilter[]
}

export interface AIActionsNode
extends Omit<EventsNode, 'fixedProperties' | 'properties' | 'math_hogql' | 'limit' | 'groupBy'> {
properties?: AIPropertyFilter[]
fixedProperties?: AIPropertyFilter[]
}

export interface ExperimentalAITrendsQuery {
kind: NodeKind.TrendsQuery
/**
Expand All @@ -931,7 +925,7 @@ export interface ExperimentalAITrendsQuery {
*/
interval?: IntervalType
/** Events and actions to include */
series: (AIEventsNode | AIActionsNode)[]
series: AIEventsNode[]
/** Properties specific to the trends insight */
trendsFilter?: TrendsFilter
/** Breakdown of the events and actions */
Expand Down
49 changes: 1 addition & 48 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4906,53 +4906,6 @@ class WebOverviewQuery(BaseModel):
useSessionsTable: Optional[bool] = None


class AIActionsNode(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
custom_name: Optional[str] = None
event: Optional[str] = Field(default=None, description="The event or `null` for all events.")
fixedProperties: Optional[
list[
Union[
EventPropertyFilter,
PersonPropertyFilter,
SessionPropertyFilter,
GroupPropertyFilter,
FeaturePropertyFilter,
]
]
] = None
kind: Literal["EventsNode"] = "EventsNode"
math: Optional[
Union[
BaseMathType,
FunnelMathType,
PropertyMathType,
CountPerActorMathType,
Literal["unique_group"],
Literal["hogql"],
]
] = None
math_group_type_index: Optional[MathGroupTypeIndex] = None
math_property: Optional[str] = None
math_property_type: Optional[str] = None
name: Optional[str] = None
orderBy: Optional[list[str]] = Field(default=None, description="Columns to order by")
properties: Optional[
list[
Union[
EventPropertyFilter,
PersonPropertyFilter,
SessionPropertyFilter,
GroupPropertyFilter,
FeaturePropertyFilter,
]
]
] = None
response: Optional[dict[str, Any]] = None


class AIEventsNode(BaseModel):
model_config = ConfigDict(
extra="forbid",
Expand Down Expand Up @@ -5129,7 +5082,7 @@ class ExperimentalAITrendsQuery(BaseModel):
]
] = Field(default=[], description="Property filters for all series")
samplingFactor: Optional[float] = Field(default=None, description="Sampling rate")
series: list[Union[AIEventsNode, AIActionsNode]] = Field(..., description="Events and actions to include")
series: list[AIEventsNode] = Field(..., description="Events and actions to include")
trendsFilter: Optional[TrendsFilter] = Field(default=None, description="Properties specific to the trends insight")


Expand Down
Loading