rootxhacker commited on
Commit
b205de0
·
verified ·
1 Parent(s): 1ef9f76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
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. Start your response with 'Code Review:' and end it with 'End of Review.'"
123
 
124
  full_result = get_completion(query, model, tokenizer)
125
 
126
- # Extract only the AI's answer
127
- start_index = full_result.find("Code Review:")
128
- end_index = full_result.find("End of Review.")
 
 
 
 
 
 
 
 
 
129
 
130
- if start_index != -1 and end_index != -1:
131
- result = full_result[start_index:end_index].strip()
132
  else:
133
- result = "Unable to generate a proper code review. Please try again."
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