Skip to content

Commit

Permalink
fix(product-assistant): improve generation prompts (#25862)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
skoob13 and github-actions[bot] authored Nov 4, 2024
1 parent 33c1a41 commit e61cf07
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 179 deletions.
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.
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 @@ -5539,14 +5483,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 @@ -917,12 +917,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 @@ -932,7 +926,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 @@ -4907,53 +4907,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 @@ -5130,7 +5083,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

0 comments on commit e61cf07

Please sign in to comment.