haystack icon indicating copy to clipboard operation
haystack copied to clipboard

feat: Add current date in UTC to PromptBuilder

Open medsriha opened this issue 1 year ago • 2 comments

Related Issues

  • fixes #issue-number

Proposed Changes:

Feature: Added a utc_now function in the PromptBuilder so the current date can be displayed inside the Template. This function returns the current date and time in UTC format as a string. The default format is %Y-%m-%d %H:%M:%S.%f, but users can specify their own format as long as it's ISO compatible. The function has also been added as a global in the Jinja2 environment, so it can be accessed directly from the template. Input validation has been implemented to ensure that the date format is valid.

How did you test it?

Added unit tests to ensure the utc_now function returns correct UTC timestamps in various formats and handles invalid date formats.

Checklist

medsriha avatar Aug 15 '24 00:08 medsriha

Pull Request Test Coverage Report for Build 10766224472

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 90.3%

Totals Coverage Status
Change from base Build 10737503702: 0.04%
Covered Lines: 7084
Relevant Lines: 7845

💛 - Coveralls

coveralls avatar Aug 15 '24 00:08 coveralls

Looks good to me but can we maybe use a syntax similar to what this extension does? I think it's more versatile and will make it easier to add functionalities in the future.

silvanocerza avatar Aug 21 '24 09:08 silvanocerza

Hey @silvanocerza I think that sounds like a good idea! Unfortunately, that's a bit more involved and @medsriha and I wouldn't have time to implement that right now. Would it be better to close this PR and open a new issue?

sjrl avatar Sep 06 '24 09:09 sjrl

Looks good to me but can we maybe use a syntax similar to what this extension does? I think it's more versatile and will make it easier to add functionalities in the future.

This version uses the same syntax as in this extension by leveraging arrow. The default date format is %Y-%m-%d %H:%M:%S. For example, you can use {% now 'UTC' %} to display the current date in UTC. Use {% now 'UTC' + 'hours=2' %} to add 2 hours to the current date, or {% now 'UTC' + 'hours=2', '%H' %} to display the number of hours after adding 2 hours to the current date. I'll update the release note if this looks good to @silvanocerza and @sjrl. Also, this will probably require adding documentation to educate on the syntax.

medsriha avatar Sep 06 '24 16:09 medsriha