mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Fix parsing questions generated by extract_questions actor into list
The previous json parsing was failing to handle questions with date filters Fix the chat actor tests to run without throwing error with freezegun complaining about importing transformers.local_llama model Remove quote escapes from date filter examples provided to extract_questions actor
This commit is contained in:
parent
279662620b
commit
48870d9170
3 changed files with 9 additions and 4 deletions
|
@ -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}")
|
||||
|
|
|
@ -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}.
|
||||
|
||||
|
|
|
@ -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
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue