redraw the figure on follow-ups that only change the numbers; add a local fake OpenAI server

"What if 6 were 4?" has no shape word, so the diagram hint never went next to
it and the tutor would answer without a new figure. When the previous user
question in the conversation had one, a soft hint (redraw only if this
continues that problem) and the same catalog sections now go along.

tools/fake_openai.py stands in for GapGPT locally so the whole tutor path can be
exercised without credit: 12 scripted answers across grades 6-12 went through
streaming, block splitting, repair, storage, history and rendering in the real
chat screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 00:43:04 +03:30
parent 0917ab487f
commit 14a4d9cbf1
5 changed files with 230 additions and 3 deletions

View File

@@ -176,9 +176,10 @@ _SLASH_READING = (
def _user_prompt(question: str, contexts: list[str], focus: str = '',
primary: bool = False) -> str:
primary: bool = False, previous: str = '') -> str:
asked = f'سوالِ دانش‌آموز: {question}'
shape_hint = diagram_mod.hint_for(f'{question}\n{focus}')
shape_hint = (diagram_mod.hint_for(f'{question}\n{focus}')
or diagram_mod.follow_up_hint_for(question, previous))
if shape_hint:
asked = f'{asked}\n\n{shape_hint}'
slash_rule = primary and '/' in question
@@ -250,8 +251,11 @@ def build_messages(question: str, context_chunks: list[dict] | None,
text = (turn.get('text') or '').strip()
if text:
messages.append({'role': role, 'content': text[:_HISTORY_CHARS]})
# سوالِ قبلیِ کاربر: «اگه به‌جای ۶ بذاریم ۴ چی؟» کلمه‌ی شکل‌دار ندارد، ولی ادامه‌ی
# همان مسئله‌ی شکل‌دار است و شکلش باید با عددِ تازه دوباره کشیده شود.
previous = next((t.get('text') or '' for t in reversed(history or []) if t.get('role') == 'user'), '')
messages.append({'role': 'user', 'content': _user_prompt(
question, contexts, focus, primary=grade_tier(grade_title) == 'primary')})
question, contexts, focus, primary=grade_tier(grade_title) == 'primary', previous=previous)})
return messages