From 3564c82af69b8ccb130085b39e5cd9564bc2f793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?th=E1=BB=8Bnh?= Date: Thu, 16 Jan 2025 15:19:49 +0700 Subject: [PATCH] Retrieve date context by question v4 --- backend/utils/llm.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backend/utils/llm.py b/backend/utils/llm.py index d844b3a9a..692db4f07 100644 --- a/backend/utils/llm.py +++ b/backend/utils/llm.py @@ -415,6 +415,27 @@ def retrieve_context_dates(messages: List[Message], tz: str) -> List[datetime]: def retrieve_context_dates_by_question(question: str, tz: str) -> List[datetime]: + prompt = f''' + You MUST determine the appropriate date range in {tz} that provides context for answering the provided. + + If the does not reference a date or a date range, respond with an empty list: [] + + Current date time in UTC: {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')} + + + {question} + + + '''.replace(' ', '').strip() + + # print(prompt) + # print(llm_mini.invoke(prompt).content) + with_parser = llm_mini.with_structured_output(DatesContext) + response: DatesContext = with_parser.invoke(prompt) + return response.dates_range + + +def retrieve_context_dates_by_question_v3(question: str, tz: str) -> List[datetime]: prompt = f''' You MUST determine the appropriate date range in {tz} that provides context for answering the question provided.