Spaces:
Paused

dushyantsingh0 commited on
Commit
8f627ba
·
1 Parent(s): ecca730

backend sprint

Browse files
Files changed (1) hide show
  1. agents/suggestion.py +4 -4
agents/suggestion.py CHANGED
@@ -22,7 +22,7 @@ def _parse_json_robust(text: str) -> dict:
22
  json_match = re.search(r'```(?:json)?\s*(\{.*?\})\s*```', text, re.DOTALL)
23
  if json_match:
24
  try:
25
- return json.loads(json_match.group(1))
26
  except json.JSONDecodeError:
27
  pass
28
 
@@ -48,7 +48,7 @@ def _parse_json_robust(text: str) -> dict:
48
  start = block.find('{')
49
  end = block.rfind('}')
50
  if start != -1 and end != -1:
51
- return json.loads(block[start:end+1])
52
  except json.JSONDecodeError:
53
  continue
54
 
@@ -58,14 +58,14 @@ def _parse_json_robust(text: str) -> dict:
58
  stripped = re.sub(r'\s*```$', '', stripped).strip()
59
 
60
  try:
61
- return json.loads(stripped)
62
  except json.JSONDecodeError as e:
63
  logger.error(f"Robust JSON parser failed. Raw text snippet: {text[:200]}...")
64
  # If we failed everything, maybe try to fix common JSON errors (like trailing commas)
65
  try:
66
  # Very basic trailing comma fix for simple JSON
67
  fixed = re.sub(r',\s*([\]}])', r'\1', stripped)
68
- return json.loads(fixed)
69
  except:
70
  raise e
71
 
 
22
  json_match = re.search(r'```(?:json)?\s*(\{.*?\})\s*```', text, re.DOTALL)
23
  if json_match:
24
  try:
25
+ return json.loads(json_match.group(1), strict=False)
26
  except json.JSONDecodeError:
27
  pass
28
 
 
48
  start = block.find('{')
49
  end = block.rfind('}')
50
  if start != -1 and end != -1:
51
+ return json.loads(block[start:end+1], strict=False)
52
  except json.JSONDecodeError:
53
  continue
54
 
 
58
  stripped = re.sub(r'\s*```$', '', stripped).strip()
59
 
60
  try:
61
+ return json.loads(stripped, strict=False)
62
  except json.JSONDecodeError as e:
63
  logger.error(f"Robust JSON parser failed. Raw text snippet: {text[:200]}...")
64
  # If we failed everything, maybe try to fix common JSON errors (like trailing commas)
65
  try:
66
  # Very basic trailing comma fix for simple JSON
67
  fixed = re.sub(r',\s*([\]}])', r'\1', stripped)
68
+ return json.loads(fixed, strict=False)
69
  except:
70
  raise e
71