Update code
Browse files- scope_router.py +77 -0
scope_router.py
CHANGED
|
@@ -72,6 +72,48 @@ CODE_PATTERNS = [
|
|
| 72 |
r"\bsyntax\b",
|
| 73 |
r"\bprogram\b",
|
| 74 |
r"\bscript\b",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
]
|
| 76 |
|
| 77 |
IMAGE_PATTERNS = [
|
|
@@ -158,6 +200,7 @@ def looks_like_code_block(text: str) -> bool:
|
|
| 158 |
"=>",
|
| 159 |
"public ",
|
| 160 |
"private ",
|
|
|
|
| 161 |
"const ",
|
| 162 |
"let ",
|
| 163 |
"var ",
|
|
@@ -166,12 +209,43 @@ def looks_like_code_block(text: str) -> bool:
|
|
| 166 |
"for (",
|
| 167 |
"while (",
|
| 168 |
"</",
|
|
|
|
|
|
|
| 169 |
]
|
| 170 |
|
| 171 |
lowered = text.lower()
|
| 172 |
return any(signal.lower() in lowered for signal in code_signals)
|
| 173 |
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
def is_code_related_request(request: CodeXRequest) -> bool:
|
| 176 |
message = normalize_text(request.message)
|
| 177 |
code = request.code or ""
|
|
@@ -192,6 +266,9 @@ def is_code_related_request(request: CodeXRequest) -> bool:
|
|
| 192 |
if contains_pattern(message, CODE_PATTERNS):
|
| 193 |
return True
|
| 194 |
|
|
|
|
|
|
|
|
|
|
| 195 |
return False
|
| 196 |
|
| 197 |
|
|
|
|
| 72 |
r"\bsyntax\b",
|
| 73 |
r"\bprogram\b",
|
| 74 |
r"\bscript\b",
|
| 75 |
+
r"\bsoftware\b",
|
| 76 |
+
r"\bbackend\b",
|
| 77 |
+
r"\bfrontend\b",
|
| 78 |
+
r"\bendpoint\b",
|
| 79 |
+
r"\bdatabase\b",
|
| 80 |
+
r"\bquery\b",
|
| 81 |
+
r"\btraceback\b",
|
| 82 |
+
r"\bdocstring\b",
|
| 83 |
+
r"\btype hints?\b",
|
| 84 |
+
r"\bvalidation\b",
|
| 85 |
+
r"\berror handling\b",
|
| 86 |
+
r"\blogging\b",
|
| 87 |
+
r"\bcomments\b",
|
| 88 |
+
r"\bexception handling\b",
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
CODE_MODIFICATION_PATTERNS = [
|
| 92 |
+
r"\badd\b",
|
| 93 |
+
r"\bupdate\b",
|
| 94 |
+
r"\bmodify\b",
|
| 95 |
+
r"\bchange\b",
|
| 96 |
+
r"\brename\b",
|
| 97 |
+
r"\bconvert\b",
|
| 98 |
+
r"\bextend\b",
|
| 99 |
+
r"\binclude\b",
|
| 100 |
+
r"\buse\b",
|
| 101 |
+
r"\breplace\b",
|
| 102 |
+
r"\bremove\b",
|
| 103 |
+
r"\bdelete\b",
|
| 104 |
+
r"\bdocstring\b",
|
| 105 |
+
r"\btype hints?\b",
|
| 106 |
+
r"\bvalidation\b",
|
| 107 |
+
r"\berror handling\b",
|
| 108 |
+
r"\blogging\b",
|
| 109 |
+
r"\bcomments\b",
|
| 110 |
+
r"\bexception handling\b",
|
| 111 |
+
r"\bmake it\b",
|
| 112 |
+
r"\bturn this into\b",
|
| 113 |
+
r"\badd support for\b",
|
| 114 |
+
r"\bnow add\b",
|
| 115 |
+
r"\bnow update\b",
|
| 116 |
+
r"\bnow change\b",
|
| 117 |
]
|
| 118 |
|
| 119 |
IMAGE_PATTERNS = [
|
|
|
|
| 200 |
"=>",
|
| 201 |
"public ",
|
| 202 |
"private ",
|
| 203 |
+
"protected ",
|
| 204 |
"const ",
|
| 205 |
"let ",
|
| 206 |
"var ",
|
|
|
|
| 209 |
"for (",
|
| 210 |
"while (",
|
| 211 |
"</",
|
| 212 |
+
"try:",
|
| 213 |
+
"except:",
|
| 214 |
]
|
| 215 |
|
| 216 |
lowered = text.lower()
|
| 217 |
return any(signal.lower() in lowered for signal in code_signals)
|
| 218 |
|
| 219 |
|
| 220 |
+
def is_follow_up_code_request(request: CodeXRequest) -> bool:
|
| 221 |
+
message = normalize_text(request.message)
|
| 222 |
+
|
| 223 |
+
has_session = bool(request.session_id and str(request.session_id).strip())
|
| 224 |
+
has_previous_context = bool(request.previous_context and str(request.previous_context).strip())
|
| 225 |
+
|
| 226 |
+
if not (has_session or has_previous_context):
|
| 227 |
+
return False
|
| 228 |
+
|
| 229 |
+
if contains_pattern(message, CODE_MODIFICATION_PATTERNS):
|
| 230 |
+
return True
|
| 231 |
+
|
| 232 |
+
short_follow_up_phrases = [
|
| 233 |
+
"now add",
|
| 234 |
+
"now update",
|
| 235 |
+
"now change",
|
| 236 |
+
"now remove",
|
| 237 |
+
"now use",
|
| 238 |
+
"add this",
|
| 239 |
+
"update this",
|
| 240 |
+
"change this",
|
| 241 |
+
"fix this",
|
| 242 |
+
"refactor this",
|
| 243 |
+
"review this",
|
| 244 |
+
]
|
| 245 |
+
|
| 246 |
+
return any(phrase in message for phrase in short_follow_up_phrases)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
def is_code_related_request(request: CodeXRequest) -> bool:
|
| 250 |
message = normalize_text(request.message)
|
| 251 |
code = request.code or ""
|
|
|
|
| 266 |
if contains_pattern(message, CODE_PATTERNS):
|
| 267 |
return True
|
| 268 |
|
| 269 |
+
if is_follow_up_code_request(request):
|
| 270 |
+
return True
|
| 271 |
+
|
| 272 |
return False
|
| 273 |
|
| 274 |
|