j-js commited on
Commit
088b8eb
·
verified ·
1 Parent(s): 0d6223f

Update conversation_logic.py

Browse files
Files changed (1) hide show
  1. conversation_logic.py +54 -18
conversation_logic.py CHANGED
@@ -55,6 +55,16 @@ FOLLOWUP_ONLY_INPUTS = {
55
  "can i have a hint",
56
  "next hint",
57
  "another hint",
 
 
 
 
 
 
 
 
 
 
58
  "next step",
59
  "continue",
60
  "go on",
@@ -299,7 +309,23 @@ def _classify_input_type(raw_user_text: str) -> str:
299
 
300
  if text in {"hint", "a hint", "give me a hint", "can i have a hint"} or text.startswith("hint:"):
301
  return "hint"
302
- if text in {"next hint", "another hint", "more hint", "more hints", "next step", "continue", "go on"} or text.startswith("next hint:"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  return "next_hint"
304
  if any(
305
  x in text
@@ -1028,8 +1054,14 @@ def _should_prefer_question_support(help_mode: str, fallback_pack: Dict[str, Any
1028
  if not fallback_pack:
1029
  return False
1030
  support_source = str(fallback_pack.get("support_source", "")).strip().lower()
1031
- has_specific_content = support_source in {"question_bank", "question_id", "question_text"}
1032
- if help_mode in {"hint", "walkthrough", "instruction", "step_by_step", "explain"}:
 
 
 
 
 
 
1033
  return has_specific_content or bool(fallback_pack)
1034
  return False
1035
 
@@ -1211,7 +1243,7 @@ class ConversationEngine:
1211
  result.help_mode = resolved_help_mode
1212
  result.meta = result.meta or {}
1213
  result.meta["hint_stage"] = hint_stage
1214
- result.meta["max_stage"] = 3
1215
  result.meta["recovered_question_text"] = solver_input
1216
  result.meta["question_id"] = question_id
1217
  result.meta["classified_topic"] = question_topic if question_topic else "general"
@@ -1289,14 +1321,21 @@ class ConversationEngine:
1289
  if input_type in {"hint", "next_hint"}:
1290
  hint_lines: List[str] = []
1291
 
1292
- custom_ladder = _question_specific_hint_ladder(
1293
- question_text=solver_input,
1294
- options_text=options_text,
1295
- classified_topic=question_topic,
1296
- )
1297
- if custom_ladder:
1298
- idx = min(max(hint_stage - 1, 0), len(custom_ladder) - 1)
1299
- hint_lines = [custom_ladder[idx]]
 
 
 
 
 
 
 
1300
 
1301
  if not hint_lines and explainer_scaffold:
1302
  ladder = _safe_meta_list(explainer_scaffold.get("hint_ladder", []))
@@ -1311,12 +1350,6 @@ class ConversationEngine:
1311
  elif next_hint_text:
1312
  hint_lines = [next_hint_text]
1313
 
1314
- if not hint_lines and fallback_pack:
1315
- fallback_hints = _safe_meta_list(fallback_pack.get("hint_ladder", []))
1316
- if fallback_hints:
1317
- idx = min(max(hint_stage - 1, 0), len(fallback_hints) - 1)
1318
- hint_lines = [fallback_hints[idx]]
1319
-
1320
  if not hint_lines and fallback_reply_core:
1321
  split_lines = [line.strip("- ").strip() for line in fallback_reply_core.splitlines() if line.strip()]
1322
  if split_lines:
@@ -1344,6 +1377,7 @@ class ConversationEngine:
1344
 
1345
  elif question_specific_reply_core and (
1346
  input_type not in {"hint", "next_hint"}
 
1347
  and (
1348
  _is_help_first_mode(resolved_help_mode)
1349
  or input_type in {"other", "confusion"}
@@ -1353,6 +1387,8 @@ class ConversationEngine:
1353
  "how do i solve",
1354
  "what do i do first",
1355
  "what should i do first",
 
 
1356
  "how should i start",
1357
  ]
1358
  )
 
55
  "can i have a hint",
56
  "next hint",
57
  "another hint",
58
+ "more hint",
59
+ "more hints",
60
+ "second hint",
61
+ "third hint",
62
+ "second next hint",
63
+ "what do i do first",
64
+ "what should i do first",
65
+ "what do i do next",
66
+ "what should i do next",
67
+ "first step",
68
  "next step",
69
  "continue",
70
  "go on",
 
309
 
310
  if text in {"hint", "a hint", "give me a hint", "can i have a hint"} or text.startswith("hint:"):
311
  return "hint"
312
+ if any(
313
+ phrase in text
314
+ for phrase in [
315
+ "next hint",
316
+ "another hint",
317
+ "more hint",
318
+ "more hints",
319
+ "second hint",
320
+ "third hint",
321
+ "second next hint",
322
+ "what do i do next",
323
+ "what should i do next",
324
+ "next step",
325
+ "continue",
326
+ "go on",
327
+ ]
328
+ ) or text.startswith("next hint:"):
329
  return "next_hint"
330
  if any(
331
  x in text
 
1054
  if not fallback_pack:
1055
  return False
1056
  support_source = str(fallback_pack.get("support_source", "")).strip().lower()
1057
+ has_specific_content = support_source in {
1058
+ "question_bank",
1059
+ "question_bank_refined",
1060
+ "question_id",
1061
+ "question_text",
1062
+ "generated_question_specific",
1063
+ }
1064
+ if help_mode in {"hint", "walkthrough", "instruction", "step_by_step", "explain", "method"}:
1065
  return has_specific_content or bool(fallback_pack)
1066
  return False
1067
 
 
1243
  result.help_mode = resolved_help_mode
1244
  result.meta = result.meta or {}
1245
  result.meta["hint_stage"] = hint_stage
1246
+ result.meta["max_stage"] = 4
1247
  result.meta["recovered_question_text"] = solver_input
1248
  result.meta["question_id"] = question_id
1249
  result.meta["classified_topic"] = question_topic if question_topic else "general"
 
1321
  if input_type in {"hint", "next_hint"}:
1322
  hint_lines: List[str] = []
1323
 
1324
+ if fallback_pack:
1325
+ fallback_hints = _safe_meta_list(fallback_pack.get("hint_ladder", []))
1326
+ if fallback_hints:
1327
+ idx = min(max(hint_stage - 1, 0), len(fallback_hints) - 1)
1328
+ hint_lines = [fallback_hints[idx]]
1329
+
1330
+ if not hint_lines:
1331
+ custom_ladder = _question_specific_hint_ladder(
1332
+ question_text=solver_input,
1333
+ options_text=options_text,
1334
+ classified_topic=question_topic,
1335
+ )
1336
+ if custom_ladder:
1337
+ idx = min(max(hint_stage - 1, 0), len(custom_ladder) - 1)
1338
+ hint_lines = [custom_ladder[idx]]
1339
 
1340
  if not hint_lines and explainer_scaffold:
1341
  ladder = _safe_meta_list(explainer_scaffold.get("hint_ladder", []))
 
1350
  elif next_hint_text:
1351
  hint_lines = [next_hint_text]
1352
 
 
 
 
 
 
 
1353
  if not hint_lines and fallback_reply_core:
1354
  split_lines = [line.strip("- ").strip() for line in fallback_reply_core.splitlines() if line.strip()]
1355
  if split_lines:
 
1377
 
1378
  elif question_specific_reply_core and (
1379
  input_type not in {"hint", "next_hint"}
1380
+ and not (prefer_question_support and fallback_reply_core)
1381
  and (
1382
  _is_help_first_mode(resolved_help_mode)
1383
  or input_type in {"other", "confusion"}
 
1387
  "how do i solve",
1388
  "what do i do first",
1389
  "what should i do first",
1390
+ "what do i do next",
1391
+ "what should i do next",
1392
  "how should i start",
1393
  ]
1394
  )