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(assistant): include current time in the taxonomy agent and in the schema generator #28147

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

skoob13
Copy link
Contributor

@skoob13 skoob13 commented Jan 31, 2025

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

  • Inject the current date in the project timezone.
  • Add evals. Apparently, it was very easy to reproduce.

Does this work well for both Cloud and self-hosted?

No

How did you test this code?

Evals

@skoob13 skoob13 requested a review from Twixes January 31, 2025 16:57
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

Comment on lines +90 to +92
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
Copy link
Contributor

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.

Suggested change
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

Comment on lines 54 to 59
- property filter 1
- person
- name
- equals
- John
2. $pageview
Copy link
Contributor

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

Comment on lines +63 to +66
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
)
Copy link
Contributor

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

Suggested change
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

Comment on lines +77 to +80
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
)
Copy link
Contributor

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,
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant