From d68243a3fb5e8b077dbd2d608e0a58ec4abea628 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Mon, 11 Nov 2024 21:05:17 -0800 Subject: [PATCH] Revert clean_json logic temporarily. Eventually, we should do better validation here to extract markdown-formatted json. --- src/khoj/processor/conversation/utils.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index 39c1765b..3fb341ea 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -527,25 +527,7 @@ def reciprocal_conversation_to_chatml(message_pair): def clean_json(response: str): """Remove any markdown json codeblock and newline formatting if present. Useful for non schema enforceable models""" - try: - # Remove markdown code blocks - cleaned = response.strip().replace("```json", "").replace("```", "") - - # Find JSON array/object pattern - json_match = re.search(r"\[.*\]|\{.*\}", cleaned, re.DOTALL) - if not json_match: - return "" - - # Extract matched JSON - json_str = json_match.group() - - # Validate by parsing - json.loads(json_str) - - return json_str.strip() - - except (json.JSONDecodeError, AttributeError): - return "" + return response.strip().replace("\n", "").removeprefix("```json").removesuffix("```") def clean_code_python(code: str):