hashan-7 commited on
Commit
501fad2
·
verified ·
1 Parent(s): 18ccd52

Update code

Browse files
Files changed (1) hide show
  1. response_formatter.py +46 -4
response_formatter.py CHANGED
@@ -72,12 +72,54 @@ def strip_structured_sections(text: str) -> str:
72
  return clean_text(text)
73
 
74
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  def first_sentence(text: str) -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  text = clean_text(text)
77
  if not text:
78
  return ""
79
- match = re.split(r"(?<=[.!?])\s+", text, maxsplit=1)
80
- return clean_text(match[0]) if match else text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
 
83
  def build_main_answer(
@@ -116,9 +158,9 @@ def build_main_answer(
116
  if task_type == CodeTaskType.REVIEW:
117
  review = extract_section(cleaned, "Review")
118
  if review:
119
- return first_sentence(review)
120
  if explanation:
121
- return first_sentence(explanation)
122
  stripped = strip_structured_sections(cleaned)
123
  if stripped:
124
  return first_sentence(stripped)
 
72
  return clean_text(text)
73
 
74
 
75
+ def normalize_summary_text(text: str) -> str:
76
+ text = clean_text(text)
77
+ if not text:
78
+ return ""
79
+
80
+ text = re.sub(r"^\d+\.\s*$", "", text).strip()
81
+ text = re.sub(r"^\d+\.\s+", "", text)
82
+ text = re.sub(r"^[-*]\s+", "", text)
83
+ text = re.sub(r"^\(\d+\)\s+", "", text)
84
+ return clean_text(text)
85
+
86
+
87
  def first_sentence(text: str) -> str:
88
+ text = normalize_summary_text(text)
89
+ if not text:
90
+ return ""
91
+
92
+ sentences = re.split(r"(?<=[.!?])\s+", text)
93
+ for sentence in sentences:
94
+ cleaned = normalize_summary_text(sentence)
95
+ if cleaned and cleaned not in {"1.", "2.", "3.", "4.", "5."}:
96
+ return cleaned
97
+
98
+ return text
99
+
100
+
101
+ def first_meaningful_line(text: str) -> str:
102
  text = clean_text(text)
103
  if not text:
104
  return ""
105
+
106
+ for line in text.splitlines():
107
+ cleaned = normalize_summary_text(line)
108
+ if not cleaned:
109
+ continue
110
+ if cleaned.lower().startswith("suggestions:"):
111
+ continue
112
+ if cleaned not in {"1.", "2.", "3.", "4.", "5."}:
113
+ return cleaned
114
+
115
+ return ""
116
+
117
+
118
+ def build_review_summary(review_text: str) -> str:
119
+ first_line = first_meaningful_line(review_text)
120
+ if first_line:
121
+ return first_sentence(first_line)
122
+ return "Code review completed."
123
 
124
 
125
  def build_main_answer(
 
158
  if task_type == CodeTaskType.REVIEW:
159
  review = extract_section(cleaned, "Review")
160
  if review:
161
+ return build_review_summary(review)
162
  if explanation:
163
+ return build_review_summary(explanation)
164
  stripped = strip_structured_sections(cleaned)
165
  if stripped:
166
  return first_sentence(stripped)