deepset-ai / haystack

:mag: AI orchestration framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data. With advanced retrieval methods, it's best suited for building RAG, question answering, semantic search or conversational agent chatbots.
https://haystack.deepset.ai
Apache License 2.0
16.94k stars 1.85k forks source link

feat: Add current date in UTC to PromptBuilder #8233

Closed medsriha closed 2 weeks ago

medsriha commented 1 month ago

Related Issues

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

coveralls commented 1 month ago

Pull Request Test Coverage Report for Build 10766224472

Details


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

💛 - Coveralls
silvanocerza commented 1 month ago

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.

sjrl commented 3 weeks ago

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?

medsriha commented 3 weeks ago

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.