update code
Browse files- code_router.py +55 -4
code_router.py
CHANGED
|
@@ -54,6 +54,38 @@ REVIEW_PATTERNS = [
|
|
| 54 |
r"\bcode review\b",
|
| 55 |
]
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
def normalize_text(text: str) -> str:
|
| 59 |
text = text or ""
|
|
@@ -66,6 +98,14 @@ def contains_pattern(text: str, patterns: list[str]) -> bool:
|
|
| 66 |
return any(re.search(pattern, text) for pattern in patterns)
|
| 67 |
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
def detect_task_type(
|
| 70 |
message: str,
|
| 71 |
code: str | None = None,
|
|
@@ -85,19 +125,30 @@ def detect_task_type(
|
|
| 85 |
if contains_pattern(normalized_message, FIX_PATTERNS):
|
| 86 |
return CodeTaskType.FIX
|
| 87 |
|
| 88 |
-
if contains_pattern(normalized_message,
|
| 89 |
-
return CodeTaskType.
|
| 90 |
|
| 91 |
if contains_pattern(normalized_message, REFACTOR_PATTERNS):
|
| 92 |
return CodeTaskType.REFACTOR
|
| 93 |
|
| 94 |
-
if
|
| 95 |
-
return CodeTaskType.
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
if contains_pattern(normalized_message, GENERATE_PATTERNS):
|
| 98 |
return CodeTaskType.GENERATE
|
| 99 |
|
|
|
|
|
|
|
|
|
|
| 100 |
if has_code and not has_error:
|
|
|
|
|
|
|
| 101 |
return CodeTaskType.EXPLAIN
|
| 102 |
|
|
|
|
|
|
|
|
|
|
| 103 |
return CodeTaskType.UNKNOWN
|
|
|
|
| 54 |
r"\bcode review\b",
|
| 55 |
]
|
| 56 |
|
| 57 |
+
MODIFICATION_PATTERNS = [
|
| 58 |
+
r"\badd\b",
|
| 59 |
+
r"\bupdate\b",
|
| 60 |
+
r"\bmodify\b",
|
| 61 |
+
r"\bchange\b",
|
| 62 |
+
r"\brename\b",
|
| 63 |
+
r"\bconvert\b",
|
| 64 |
+
r"\bextend\b",
|
| 65 |
+
r"\binclude\b",
|
| 66 |
+
r"\buse\b",
|
| 67 |
+
r"\breplace\b",
|
| 68 |
+
r"\bremove\b",
|
| 69 |
+
r"\bdelete\b",
|
| 70 |
+
r"\bdocstring\b",
|
| 71 |
+
r"\btype hints?\b",
|
| 72 |
+
r"\bvalidation\b",
|
| 73 |
+
r"\berror handling\b",
|
| 74 |
+
r"\blogging\b",
|
| 75 |
+
r"\bcomments\b",
|
| 76 |
+
r"\bexception handling\b",
|
| 77 |
+
r"\bmake it\b",
|
| 78 |
+
r"\bturn this into\b",
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
DIRECT_EXPLAIN_ONLY_PATTERNS = [
|
| 82 |
+
r"\bexplain\b",
|
| 83 |
+
r"\bwhat does this do\b",
|
| 84 |
+
r"\bhow does this work\b",
|
| 85 |
+
r"\bdescribe this code\b",
|
| 86 |
+
r"\bhelp me understand\b",
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
|
| 90 |
def normalize_text(text: str) -> str:
|
| 91 |
text = text or ""
|
|
|
|
| 98 |
return any(re.search(pattern, text) for pattern in patterns)
|
| 99 |
|
| 100 |
|
| 101 |
+
def is_modification_request(text: str) -> bool:
|
| 102 |
+
return contains_pattern(text, MODIFICATION_PATTERNS)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def is_direct_explanation_request(text: str) -> bool:
|
| 106 |
+
return contains_pattern(text, DIRECT_EXPLAIN_ONLY_PATTERNS)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
def detect_task_type(
|
| 110 |
message: str,
|
| 111 |
code: str | None = None,
|
|
|
|
| 125 |
if contains_pattern(normalized_message, FIX_PATTERNS):
|
| 126 |
return CodeTaskType.FIX
|
| 127 |
|
| 128 |
+
if contains_pattern(normalized_message, REVIEW_PATTERNS):
|
| 129 |
+
return CodeTaskType.REVIEW
|
| 130 |
|
| 131 |
if contains_pattern(normalized_message, REFACTOR_PATTERNS):
|
| 132 |
return CodeTaskType.REFACTOR
|
| 133 |
|
| 134 |
+
if is_direct_explanation_request(normalized_message) and not is_modification_request(normalized_message):
|
| 135 |
+
return CodeTaskType.EXPLAIN
|
| 136 |
+
|
| 137 |
+
if has_code and is_modification_request(normalized_message):
|
| 138 |
+
return CodeTaskType.REFACTOR
|
| 139 |
|
| 140 |
if contains_pattern(normalized_message, GENERATE_PATTERNS):
|
| 141 |
return CodeTaskType.GENERATE
|
| 142 |
|
| 143 |
+
if contains_pattern(normalized_message, EXPLAIN_PATTERNS) and not is_modification_request(normalized_message):
|
| 144 |
+
return CodeTaskType.EXPLAIN
|
| 145 |
+
|
| 146 |
if has_code and not has_error:
|
| 147 |
+
if is_modification_request(normalized_message):
|
| 148 |
+
return CodeTaskType.REFACTOR
|
| 149 |
return CodeTaskType.EXPLAIN
|
| 150 |
|
| 151 |
+
if is_modification_request(normalized_message):
|
| 152 |
+
return CodeTaskType.GENERATE
|
| 153 |
+
|
| 154 |
return CodeTaskType.UNKNOWN
|