mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Revert clean_json logic temporarily. Eventually, we should do better validation here to extract markdown-formatted json.
This commit is contained in:
parent
1cab6c081f
commit
d68243a3fb
1 changed files with 1 additions and 19 deletions
|
@ -527,25 +527,7 @@ def reciprocal_conversation_to_chatml(message_pair):
|
||||||
|
|
||||||
def clean_json(response: str):
|
def clean_json(response: str):
|
||||||
"""Remove any markdown json codeblock and newline formatting if present. Useful for non schema enforceable models"""
|
"""Remove any markdown json codeblock and newline formatting if present. Useful for non schema enforceable models"""
|
||||||
try:
|
return response.strip().replace("\n", "").removeprefix("```json").removesuffix("```")
|
||||||
# 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 ""
|
|
||||||
|
|
||||||
|
|
||||||
def clean_code_python(code: str):
|
def clean_code_python(code: str):
|
||||||
|
|
Loading…
Reference in a new issue