Update code
Browse files- context_manager.py +36 -2
context_manager.py
CHANGED
|
@@ -13,8 +13,13 @@ FOLLOW_UP_PATTERNS = [
|
|
| 13 |
"explain this",
|
| 14 |
"review this",
|
| 15 |
"add validation",
|
|
|
|
|
|
|
| 16 |
"add error handling",
|
| 17 |
"add comments",
|
|
|
|
|
|
|
|
|
|
| 18 |
"optimize this",
|
| 19 |
"continue this",
|
| 20 |
"continue from above",
|
|
@@ -24,6 +29,11 @@ FOLLOW_UP_PATTERNS = [
|
|
| 24 |
"the above code",
|
| 25 |
"use the previous code",
|
| 26 |
"based on the previous code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
]
|
| 28 |
|
| 29 |
|
|
@@ -89,7 +99,26 @@ class ContextManager:
|
|
| 89 |
if not message:
|
| 90 |
return False
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
def enrich_request_with_context(
|
| 95 |
self,
|
|
@@ -115,10 +144,15 @@ class ContextManager:
|
|
| 115 |
if request.previous_context and request.previous_context.strip():
|
| 116 |
previous_context_parts.append(request.previous_context.strip())
|
| 117 |
|
| 118 |
-
merged_previous_context =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
return CodeXRequest(
|
| 121 |
message=request.message,
|
|
|
|
| 122 |
mode=request.mode,
|
| 123 |
language=enriched_language,
|
| 124 |
code=artifact.code,
|
|
|
|
| 13 |
"explain this",
|
| 14 |
"review this",
|
| 15 |
"add validation",
|
| 16 |
+
"input validation",
|
| 17 |
+
"add input validation",
|
| 18 |
"add error handling",
|
| 19 |
"add comments",
|
| 20 |
+
"add logging",
|
| 21 |
+
"add docstring",
|
| 22 |
+
"add type hints",
|
| 23 |
"optimize this",
|
| 24 |
"continue this",
|
| 25 |
"continue from above",
|
|
|
|
| 29 |
"the above code",
|
| 30 |
"use the previous code",
|
| 31 |
"based on the previous code",
|
| 32 |
+
"now add",
|
| 33 |
+
"now update",
|
| 34 |
+
"now change",
|
| 35 |
+
"now remove",
|
| 36 |
+
"now use",
|
| 37 |
]
|
| 38 |
|
| 39 |
|
|
|
|
| 99 |
if not message:
|
| 100 |
return False
|
| 101 |
|
| 102 |
+
if any(pattern in message for pattern in FOLLOW_UP_PATTERNS):
|
| 103 |
+
return True
|
| 104 |
+
|
| 105 |
+
loose_follow_up_signals = [
|
| 106 |
+
"add ",
|
| 107 |
+
"update ",
|
| 108 |
+
"change ",
|
| 109 |
+
"modify ",
|
| 110 |
+
"remove ",
|
| 111 |
+
"replace ",
|
| 112 |
+
"rename ",
|
| 113 |
+
"use ",
|
| 114 |
+
"include ",
|
| 115 |
+
]
|
| 116 |
+
|
| 117 |
+
has_session = bool(request.session_id and str(request.session_id).strip())
|
| 118 |
+
if has_session and any(signal in message for signal in loose_follow_up_signals):
|
| 119 |
+
return True
|
| 120 |
+
|
| 121 |
+
return False
|
| 122 |
|
| 123 |
def enrich_request_with_context(
|
| 124 |
self,
|
|
|
|
| 144 |
if request.previous_context and request.previous_context.strip():
|
| 145 |
previous_context_parts.append(request.previous_context.strip())
|
| 146 |
|
| 147 |
+
merged_previous_context = (
|
| 148 |
+
"\n\n".join(previous_context_parts)
|
| 149 |
+
if previous_context_parts
|
| 150 |
+
else request.previous_context
|
| 151 |
+
)
|
| 152 |
|
| 153 |
return CodeXRequest(
|
| 154 |
message=request.message,
|
| 155 |
+
session_id=request.session_id,
|
| 156 |
mode=request.mode,
|
| 157 |
language=enriched_language,
|
| 158 |
code=artifact.code,
|