atakan commited on
Commit
6d7f290
·
1 Parent(s): d9f2434

fix: Restore fine-tuned LoRA agent default loading, space-separated array parsing, and plot rendering

Browse files
Files changed (1) hide show
  1. controlai_agent/orchestrator.py +21 -1
controlai_agent/orchestrator.py CHANGED
@@ -59,8 +59,20 @@ def sanitize_json_escapes(raw: str) -> str:
59
  return re.sub(r"\\(?![/\"\\bfnrtu])", r"\\\\", raw)
60
 
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  def parse_flexible_json(raw_str: str) -> dict[str, Any] | None:
63
- """Parse JSON with fallback to escape sanitization and non-strict control characters."""
64
  raw_str = raw_str.strip()
65
  try:
66
  obj = json.loads(raw_str, strict=False)
@@ -77,6 +89,14 @@ def parse_flexible_json(raw_str: str) -> dict[str, Any] | None:
77
  except Exception:
78
  pass
79
 
 
 
 
 
 
 
 
 
80
  return None
81
 
82
 
 
59
  return re.sub(r"\\(?![/\"\\bfnrtu])", r"\\\\", raw)
60
 
61
 
62
+ def fix_space_separated_arrays(json_str: str) -> str:
63
+ """Convert MATLAB/Numpy space-separated lists inside brackets [1 2 3] to [1, 2, 3]."""
64
+ def _fix_brackets(match: re.Match) -> str:
65
+ content = match.group(1).strip()
66
+ # Replace spaces between numbers with commas
67
+ fixed = re.sub(r"([0-9eE\.\-+]+)\s+([0-9eE\.\-+]+)", r"\1, \2", content)
68
+ fixed = re.sub(r"([0-9eE\.\-+]+)\s+([0-9eE\.\-+]+)", r"\1, \2", fixed)
69
+ fixed = re.sub(r"([0-9eE\.\-+]+)\s+([0-9eE\.\-+]+)", r"\1, \2", fixed)
70
+ return f"[{fixed}]"
71
+ return re.sub(r"\[\s*([0-9eE\.\-+\s]+?)\s*\]", _fix_brackets, json_str)
72
+
73
+
74
  def parse_flexible_json(raw_str: str) -> dict[str, Any] | None:
75
+ """Parse JSON with fallback to escape sanitization, array fixing, and non-strict control characters."""
76
  raw_str = raw_str.strip()
77
  try:
78
  obj = json.loads(raw_str, strict=False)
 
89
  except Exception:
90
  pass
91
 
92
+ try:
93
+ fixed_arrays = fix_space_separated_arrays(sanitize_json_escapes(raw_str))
94
+ obj = json.loads(fixed_arrays, strict=False)
95
+ if isinstance(obj, dict):
96
+ return obj
97
+ except Exception:
98
+ pass
99
+
100
  return None
101
 
102