Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -119,18 +119,27 @@ Now, review the following code using this approach:
|
|
| 119 |
"""
|
| 120 |
|
| 121 |
# Concatenate the prompt with the code to analyze
|
| 122 |
-
query = few_shot_prompt + "\n\n" + code_to_analyze + "\n\nProvide a detailed review following the structure above, including understanding the code, identifying potential security issues, identifying potential logic vulnerabilities, and offering specific suggestions for improvement.
|
| 123 |
|
| 124 |
full_result = get_completion(query, model, tokenizer)
|
| 125 |
|
| 126 |
-
#
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
if
|
| 131 |
-
result =
|
| 132 |
else:
|
| 133 |
-
result =
|
| 134 |
|
| 135 |
return result
|
| 136 |
|
|
|
|
| 119 |
"""
|
| 120 |
|
| 121 |
# Concatenate the prompt with the code to analyze
|
| 122 |
+
query = few_shot_prompt + "\n\n" + code_to_analyze + "\n\nProvide a detailed review following the structure above, including understanding the code, identifying potential security issues, identifying potential logic vulnerabilities, and offering specific suggestions for improvement."
|
| 123 |
|
| 124 |
full_result = get_completion(query, model, tokenizer)
|
| 125 |
|
| 126 |
+
# Process the output
|
| 127 |
+
lines = full_result.split('\n')
|
| 128 |
+
processed_lines = []
|
| 129 |
+
in_review = False
|
| 130 |
+
for line in lines:
|
| 131 |
+
if line.strip().lower().startswith("code review:"):
|
| 132 |
+
in_review = True
|
| 133 |
+
continue
|
| 134 |
+
if line.strip().lower() == "end of review.":
|
| 135 |
+
break
|
| 136 |
+
if in_review:
|
| 137 |
+
processed_lines.append(line)
|
| 138 |
|
| 139 |
+
if processed_lines:
|
| 140 |
+
result = "\n".join(processed_lines).strip()
|
| 141 |
else:
|
| 142 |
+
result = full_result.strip() # If no markers found, return the full result
|
| 143 |
|
| 144 |
return result
|
| 145 |
|