naman1102 commited on
Commit
9f8e537
·
1 Parent(s): e9db129

Update analyzer.py

Browse files
Files changed (1) hide show
  1. analyzer.py +8 -1
analyzer.py CHANGED
@@ -31,7 +31,14 @@ def analyze_code(code: str) -> str:
31
 
32
  def parse_llm_json_response(response: str):
33
  try:
34
- return json.loads(response)
 
 
 
 
 
 
 
35
  except Exception as e:
36
  return {"error": f"Failed to parse JSON: {e}", "raw": response}
37
 
 
31
 
32
  def parse_llm_json_response(response: str):
33
  try:
34
+ # Extract only the substring between the first '{' and the last '}'
35
+ start = response.find('{')
36
+ end = response.rfind('}')
37
+ if start != -1 and end != -1 and end > start:
38
+ json_str = response[start:end+1]
39
+ else:
40
+ json_str = response
41
+ return json.loads(json_str)
42
  except Exception as e:
43
  return {"error": f"Failed to parse JSON: {e}", "raw": response}
44