Update date filter to allow quoting values in single quotes

This commit is contained in:
Debanjum Singh Solanky 2023-07-07 17:13:47 -07:00
parent e588f7c528
commit 171ce19e1f
3 changed files with 11 additions and 11 deletions

View file

@ -102,7 +102,7 @@ A: You visited the Angkor Wat Temple in Cambodia with Pablo, Namita and Xi.
Q: What national parks did I go to last year? Q: What national parks did I go to last year?
["National park I visited in {last_new_year} dt>="{last_new_year_date}" dt<"{current_new_year_date}""] ["National park I visited in {last_new_year} dt>='{last_new_year_date}' dt<'{current_new_year_date}'"]
A: You visited the Grand Canyon and Yellowstone National Park in {last_new_year}. A: You visited the Grand Canyon and Yellowstone National Park in {last_new_year}.

View file

@ -23,7 +23,7 @@ class DateFilter(BaseFilter):
# - dt>="yesterday" dt<"tomorrow" # - dt>="yesterday" dt<"tomorrow"
# - dt>="last week" # - dt>="last week"
# - dt:"2 years ago" # - dt:"2 years ago"
date_regex = r"dt([:><=]{1,2})\"(.*?)\"" date_regex = r"dt([:><=]{1,2})[\"'](.*?)[\"']"
def __init__(self, entry_key="raw"): def __init__(self, entry_key="raw"):
self.entry_key = entry_key self.entry_key = entry_key

View file

@ -33,9 +33,9 @@ def test_extract_question_with_date_filter_from_relative_day():
# Assert # Assert
expected_responses = [ expected_responses = [
('dt="1984-04-01"', ""), ("dt='1984-04-01'", ""),
('dt>="1984-04-01"', 'dt<"1984-04-02"'), ("dt>='1984-04-01'", "dt<'1984-04-02'"),
('dt>"1984-03-31"', 'dt<"1984-04-02"'), ("dt>'1984-03-31'", "dt<'1984-04-02'"),
] ]
assert len(response) == 1 assert len(response) == 1
assert any([start in response[0] and end in response[0] for start, end in expected_responses]), ( assert any([start in response[0] and end in response[0] for start, end in expected_responses]), (
@ -51,7 +51,7 @@ def test_extract_question_with_date_filter_from_relative_month():
response = extract_questions("Which countries did I visit last month?") response = extract_questions("Which countries did I visit last month?")
# Assert # Assert
expected_responses = [('dt>="1984-03-01"', 'dt<"1984-04-01"'), ('dt>="1984-03-01"', 'dt<="1984-03-31"')] expected_responses = [("dt>='1984-03-01'", "dt<'1984-04-01'"), ("dt>='1984-03-01'", "dt<='1984-03-31'")]
assert len(response) == 1 assert len(response) == 1
assert any([start in response[0] and end in response[0] for start, end in expected_responses]), ( assert any([start in response[0] and end in response[0] for start, end in expected_responses]), (
"Expected date filter to limit to March 1984 in response but got: " + response[0] "Expected date filter to limit to March 1984 in response but got: " + response[0]
@ -67,9 +67,9 @@ def test_extract_question_with_date_filter_from_relative_year():
# Assert # Assert
expected_responses = [ expected_responses = [
('dt>="1984-01-01"', ""), ("dt>='1984-01-01'", ""),
('dt>="1984-01-01"', 'dt<"1985-01-01"'), ("dt>='1984-01-01'", "dt<'1985-01-01'"),
('dt>="1984-01-01"', 'dt<="1984-12-31"'), ("dt>='1984-01-01'", "dt<='1984-12-31'"),
] ]
assert len(response) == 1 assert len(response) == 1
assert any([start in response[0] and end in response[0] for start, end in expected_responses]), ( assert any([start in response[0] and end in response[0] for start, end in expected_responses]), (
@ -172,8 +172,8 @@ def test_generate_search_query_with_date_and_context_from_chat_history():
# Assert # Assert
expected_responses = [ expected_responses = [
('dt>="2000-04-01"', 'dt<"2000-05-01"'), ("dt>='2000-04-01'", "dt<'2000-05-01'"),
('dt>="2000-04-01"', 'dt<="2000-04-31"'), ("dt>='2000-04-01'", "dt<='2000-04-30'"),
] ]
assert len(response) == 1 assert len(response) == 1
assert "Masai Mara" in response[0] assert "Masai Mara" in response[0]