Update code
Browse files- response_formatter.py +11 -11
response_formatter.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import re
|
| 2 |
-
from typing import
|
| 3 |
|
| 4 |
from schemas import CodeTaskType, CodeXResponse, ResponseMeta, RetrievedEvidence
|
| 5 |
|
|
@@ -38,8 +38,6 @@ def extract_explanation(text: str, task_type: CodeTaskType) -> Optional[str]:
|
|
| 38 |
if task_type == CodeTaskType.FIX:
|
| 39 |
root_cause = extract_section(text, "Root Cause")
|
| 40 |
explanation = extract_section(text, "Explanation")
|
| 41 |
-
if root_cause and explanation:
|
| 42 |
-
return explanation
|
| 43 |
return explanation or root_cause
|
| 44 |
|
| 45 |
if task_type == CodeTaskType.REVIEW:
|
|
@@ -49,13 +47,11 @@ def extract_explanation(text: str, task_type: CodeTaskType) -> Optional[str]:
|
|
| 49 |
return f"{review}\n\nSuggestions:\n{suggestions}"
|
| 50 |
return review or suggestions
|
| 51 |
|
| 52 |
-
if task_type
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if task_type == CodeTaskType.GENERATE:
|
| 59 |
return extract_section(text, "Explanation")
|
| 60 |
|
| 61 |
return (
|
|
@@ -133,7 +129,7 @@ def extract_original_callable_name(raw_text: str) -> Optional[str]:
|
|
| 133 |
r"\bfunction\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(",
|
| 134 |
]
|
| 135 |
for pattern in patterns:
|
| 136 |
-
match = re.search(pattern, raw_text)
|
| 137 |
if match:
|
| 138 |
return match.group(1)
|
| 139 |
return None
|
|
@@ -191,6 +187,7 @@ def should_include_code_output(
|
|
| 191 |
"could improve",
|
| 192 |
"readability",
|
| 193 |
"maintainability",
|
|
|
|
| 194 |
]
|
| 195 |
if any(signal in lowered for signal in review_only_signals):
|
| 196 |
return None
|
|
@@ -294,6 +291,9 @@ def build_response(
|
|
| 294 |
if original_name and final_name and original_name != final_name:
|
| 295 |
warnings.append("Refactor output may have changed original naming unexpectedly.")
|
| 296 |
|
|
|
|
|
|
|
|
|
|
| 297 |
return CodeXResponse(
|
| 298 |
task_type=task_type,
|
| 299 |
answer=answer,
|
|
|
|
| 1 |
import re
|
| 2 |
+
from typing import List, Optional
|
| 3 |
|
| 4 |
from schemas import CodeTaskType, CodeXResponse, ResponseMeta, RetrievedEvidence
|
| 5 |
|
|
|
|
| 38 |
if task_type == CodeTaskType.FIX:
|
| 39 |
root_cause = extract_section(text, "Root Cause")
|
| 40 |
explanation = extract_section(text, "Explanation")
|
|
|
|
|
|
|
| 41 |
return explanation or root_cause
|
| 42 |
|
| 43 |
if task_type == CodeTaskType.REVIEW:
|
|
|
|
| 47 |
return f"{review}\n\nSuggestions:\n{suggestions}"
|
| 48 |
return review or suggestions
|
| 49 |
|
| 50 |
+
if task_type in {
|
| 51 |
+
CodeTaskType.REFACTOR,
|
| 52 |
+
CodeTaskType.EXPLAIN,
|
| 53 |
+
CodeTaskType.GENERATE,
|
| 54 |
+
}:
|
|
|
|
|
|
|
| 55 |
return extract_section(text, "Explanation")
|
| 56 |
|
| 57 |
return (
|
|
|
|
| 129 |
r"\bfunction\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(",
|
| 130 |
]
|
| 131 |
for pattern in patterns:
|
| 132 |
+
match = re.search(pattern, raw_text or "")
|
| 133 |
if match:
|
| 134 |
return match.group(1)
|
| 135 |
return None
|
|
|
|
| 187 |
"could improve",
|
| 188 |
"readability",
|
| 189 |
"maintainability",
|
| 190 |
+
"edge case",
|
| 191 |
]
|
| 192 |
if any(signal in lowered for signal in review_only_signals):
|
| 193 |
return None
|
|
|
|
| 291 |
if original_name and final_name and original_name != final_name:
|
| 292 |
warnings.append("Refactor output may have changed original naming unexpectedly.")
|
| 293 |
|
| 294 |
+
if task_type == CodeTaskType.FIX and not code_output and cleaned_output:
|
| 295 |
+
warnings.append("Fix response did not include code output.")
|
| 296 |
+
|
| 297 |
return CodeXResponse(
|
| 298 |
task_type=task_type,
|
| 299 |
answer=answer,
|