Update conversation_logic.py
Browse files- conversation_logic.py +33 -7
conversation_logic.py
CHANGED
|
@@ -335,9 +335,36 @@ def _build_retrieval_query(
|
|
| 335 |
) -> str:
|
| 336 |
parts: List[str] = []
|
| 337 |
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
normalized_category = normalize_category(category)
|
| 343 |
if normalized_category and normalized_category != "General":
|
|
@@ -352,17 +379,16 @@ def _build_retrieval_query(
|
|
| 352 |
if intent in {"definition", "concept"}:
|
| 353 |
parts.append("definition concept explanation")
|
| 354 |
elif intent in {"walkthrough", "step_by_step", "method", "instruction"}:
|
| 355 |
-
parts.append("method
|
| 356 |
elif intent == "hint":
|
| 357 |
-
parts.append("
|
| 358 |
elif intent == "explain":
|
| 359 |
-
parts.append("explanation reasoning")
|
| 360 |
elif not solved:
|
| 361 |
parts.append("teaching explanation method")
|
| 362 |
|
| 363 |
return " ".join(parts).strip()
|
| 364 |
|
| 365 |
-
|
| 366 |
class ConversationEngine:
|
| 367 |
def __init__(
|
| 368 |
self,
|
|
|
|
| 335 |
) -> str:
|
| 336 |
parts: List[str] = []
|
| 337 |
|
| 338 |
+
raw = (raw_user_text or "").strip()
|
| 339 |
+
question = (question_text or "").strip()
|
| 340 |
+
|
| 341 |
+
# Prefer the actual math content, not the conversational wrapper
|
| 342 |
+
if question:
|
| 343 |
+
parts.append(question)
|
| 344 |
+
elif raw:
|
| 345 |
+
lowered = raw.lower()
|
| 346 |
+
|
| 347 |
+
wrappers = [
|
| 348 |
+
"how do i solve",
|
| 349 |
+
"how to solve",
|
| 350 |
+
"solve",
|
| 351 |
+
"can you solve",
|
| 352 |
+
"walk me through",
|
| 353 |
+
"explain",
|
| 354 |
+
"help me solve",
|
| 355 |
+
"show me how to solve",
|
| 356 |
+
]
|
| 357 |
+
|
| 358 |
+
cleaned = raw
|
| 359 |
+
for w in wrappers:
|
| 360 |
+
if lowered.startswith(w):
|
| 361 |
+
cleaned = raw[len(w):].strip(" :.-?")
|
| 362 |
+
break
|
| 363 |
+
|
| 364 |
+
if cleaned:
|
| 365 |
+
parts.append(cleaned)
|
| 366 |
+
else:
|
| 367 |
+
parts.append(raw)
|
| 368 |
|
| 369 |
normalized_category = normalize_category(category)
|
| 370 |
if normalized_category and normalized_category != "General":
|
|
|
|
| 379 |
if intent in {"definition", "concept"}:
|
| 380 |
parts.append("definition concept explanation")
|
| 381 |
elif intent in {"walkthrough", "step_by_step", "method", "instruction"}:
|
| 382 |
+
parts.append("equation solving method isolate variable worked example")
|
| 383 |
elif intent == "hint":
|
| 384 |
+
parts.append("equation solving hint first step isolate variable")
|
| 385 |
elif intent == "explain":
|
| 386 |
+
parts.append("equation solving explanation reasoning")
|
| 387 |
elif not solved:
|
| 388 |
parts.append("teaching explanation method")
|
| 389 |
|
| 390 |
return " ".join(parts).strip()
|
| 391 |
|
|
|
|
| 392 |
class ConversationEngine:
|
| 393 |
def __init__(
|
| 394 |
self,
|