Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -119,27 +119,26 @@ 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 |
# Process the output
|
127 |
lines = full_result.split('\n')
|
128 |
processed_lines = []
|
129 |
-
|
|
|
|
|
130 |
for line in lines:
|
131 |
-
if
|
132 |
-
|
133 |
-
continue
|
134 |
-
if line.strip().lower() == "end of review.":
|
135 |
-
break
|
136 |
-
if in_review:
|
137 |
processed_lines.append(line)
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
143 |
|
144 |
return result
|
145 |
|
|
|
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. Start each section with its number and title, e.g., '1. Understanding the code:'"
|
123 |
|
124 |
full_result = get_completion(query, model, tokenizer)
|
125 |
|
126 |
# Process the output
|
127 |
lines = full_result.split('\n')
|
128 |
processed_lines = []
|
129 |
+
relevant_sections = ['1. Understanding the code:', '2. Potential security issues:', '3. Potential logic vulnerabilities:', 'Suggestions:']
|
130 |
+
in_relevant_section = False
|
131 |
+
|
132 |
for line in lines:
|
133 |
+
if any(section in line for section in relevant_sections):
|
134 |
+
in_relevant_section = True
|
|
|
|
|
|
|
|
|
135 |
processed_lines.append(line)
|
136 |
+
elif in_relevant_section and line.strip():
|
137 |
+
processed_lines.append(line)
|
138 |
+
elif in_relevant_section and not line.strip():
|
139 |
+
in_relevant_section = False
|
140 |
+
|
141 |
+
result = "\n".join(processed_lines).strip()
|
142 |
|
143 |
return result
|
144 |
|