-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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(assistant): include current time in the taxonomy agent and in the schema generator #28147
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR adds timezone-aware date handling across the PostHog assistant system to fix incorrect date defaults in queries like "this month" that were previously set to 2023.
- Added
project_time
injection in/ee/hogai/utils/nodes.py
base class to standardize timezone handling across all assistant nodes - Added timezone-aware date handling in
/ee/hogai/summarizer/nodes.py
using inherited properties instead of direct datetime manipulation - Added new test cases in
/ee/hogai/eval/tests/
directory to verify current year is used in date ranges for trends, funnels, and retention queries - Added
{{project_time}}
template variable to all prompt files in/ee/hogai/*/prompts.py
to ensure consistent date context - Note: Author indicates solution doesn't work well for both cloud and self-hosted environments, which needs addressing
10 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile
year = str(datetime.now().year) | ||
assert (date_range.date_from and year in date_range.date_from) or ( | ||
date_range.date_to and year in date_range.date_to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: This assertion could fail around New Year's when the current year changes between the two checks. Consider freezing time in the test.
year = str(datetime.now().year) | |
assert (date_range.date_from and year in date_range.date_from) or ( | |
date_range.date_to and year in date_range.date_to | |
now = datetime.now() | |
year = str(now.year) | |
assert (date_range.date_from and year in date_range.date_from) or ( | |
date_range.date_to and year in date_range.date_to |
- property filter 1 | ||
- person | ||
- name | ||
- equals | ||
- John | ||
2. $pageview |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: property filter in test_current_date is irrelevant to date testing and could be removed
year = str(datetime.now().year) | ||
assert (date_range.date_from and year in date_range.date_from) or ( | ||
date_range.date_to and year in date_range.date_to | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: test could fail around new year when date_from is in previous year and date_to is in next year
year = str(datetime.now().year) | |
assert (date_range.date_from and year in date_range.date_from) or ( | |
date_range.date_to and year in date_range.date_to | |
) | |
# Get the year from either date_from or date_to since January could span years | |
year_from = datetime.strptime(date_range.date_from, "%Y-%m-%d").year if date_range.date_from else None | |
year_to = datetime.strptime(date_range.date_to, "%Y-%m-%d").year if date_range.date_to else None | |
current_year = datetime.now().year | |
assert year_from == current_year or year_to == current_year |
year = str(datetime.now().year) | ||
assert (date_range.date_from and year in date_range.date_from) or ( | ||
date_range.date_to and year in date_range.date_to | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: This assertion may fail in edge cases when testing around year boundaries. Consider using a mocked current date for more reliable testing.
message: SchemaGeneratorOutput[Q] = chain.invoke({}, config) | ||
message: SchemaGeneratorOutput[Q] = chain.invoke( | ||
{ | ||
"project_time": self.project_tz_now, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: project_time is injected but not documented in docstrings or type hints
Problem
We've received customer feedback that the date for "this month" was set to 2023. Let's specify the current time in the prompt.
Changes
Does this work well for both Cloud and self-hosted?
No
How did you test this code?
Evals