Spaces:
Running
Running
Update github_repo_analyzer.py
Browse files- github_repo_analyzer.py +16 -0
github_repo_analyzer.py
CHANGED
@@ -17,6 +17,7 @@ import json
|
|
17 |
from pathlib import Path
|
18 |
import traceback
|
19 |
import argparse
|
|
|
20 |
|
21 |
def run_semgrep(repo_path):
|
22 |
try:
|
@@ -164,6 +165,21 @@ def safe_call_llm(client, prompt, retries=3):
|
|
164 |
return []
|
165 |
|
166 |
def parse_llm_response(response):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
try:
|
168 |
# First, try to parse the entire response as JSON
|
169 |
return json.loads(response)
|
|
|
17 |
from pathlib import Path
|
18 |
import traceback
|
19 |
import argparse
|
20 |
+
import re
|
21 |
|
22 |
def run_semgrep(repo_path):
|
23 |
try:
|
|
|
165 |
return []
|
166 |
|
167 |
def parse_llm_response(response):
|
168 |
+
# Pattern to match JSON content within triple backticks, with or without 'json' specifier
|
169 |
+
pattern = r"```(?:json)?\s*([\s\S]*?)\s*```"
|
170 |
+
|
171 |
+
# Find all matches
|
172 |
+
matches = re.findall(pattern, response)
|
173 |
+
|
174 |
+
if matches:
|
175 |
+
# If we found matches, use the first one (assuming there's only one JSON block)
|
176 |
+
json_str = matches[0]
|
177 |
+
else:
|
178 |
+
# If no code blocks found, assume the entire text is JSON
|
179 |
+
json_str = response
|
180 |
+
|
181 |
+
# Strip any leading/trailing whitespace
|
182 |
+
json_str = json_str.strip()
|
183 |
try:
|
184 |
# First, try to parse the entire response as JSON
|
185 |
return json.loads(response)
|