diff --git a/src/khoj/processor/conversation/gpt.py b/src/khoj/processor/conversation/gpt.py index 423a2124..ed8ea455 100644 --- a/src/khoj/processor/conversation/gpt.py +++ b/src/khoj/processor/conversation/gpt.py @@ -110,14 +110,16 @@ def extract_questions( # Extract, Clean Message from GPT's Response try: - questions = json.loads( - # Clean response to increase likelihood of valid JSON. E.g replace ' with " to enclose strings + questions = ( response.strip(empty_escape_sequences) .replace("['", '["') .replace("']", '"]') .replace("', '", '", "') + .replace('["', "") + .replace('"]', "") + .split('", "') ) - except json.decoder.JSONDecodeError: + except: logger.warning(f"GPT returned invalid JSON. Falling back to using user message as search query.\n{response}") questions = [text] logger.debug(f"Extracted Questions by GPT: {questions}") diff --git a/src/khoj/processor/conversation/prompts.py b/src/khoj/processor/conversation/prompts.py index 2cbc9f40..04b5d108 100644 --- a/src/khoj/processor/conversation/prompts.py +++ b/src/khoj/processor/conversation/prompts.py @@ -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? -["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}. diff --git a/tests/test_chat_actors.py b/tests/test_chat_actors.py index df710ed3..524f0813 100644 --- a/tests/test_chat_actors.py +++ b/tests/test_chat_actors.py @@ -4,6 +4,7 @@ from datetime import datetime # External Packages import pytest +import freezegun from freezegun import freeze_time # Internal Packages @@ -19,6 +20,8 @@ if api_key is None: allow_module_level=True, ) +freezegun.configure(extend_ignore_list=["transformers"]) + # Test # ----------------------------------------------------------------------------------------------------