Update analyzer.py
Browse files- 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|