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:
@@ -148,6 +148,27 @@ DIAGRAM_HINT = (
|
||||
)
|
||||
|
||||
|
||||
FOLLOW_UP_HINT = (
|
||||
'اگر این سوال ادامهی همان مسئلهی شکلدارِ قبلی است (عدد یا اندازه عوض شده، یا توضیحِ بیشتر '
|
||||
'خواسته)، در پایانِ پاسخ شکلِ تازه را با عددهای تازه در بلوکِ <diagram>…</diagram> بکش؛ '
|
||||
'اگر نیست، شکل نگذار.'
|
||||
)
|
||||
|
||||
|
||||
def follow_up_hint_for(question: str, previous: str) -> str:
|
||||
"""
|
||||
سوالِ ادامهای بیکلمهی شکلدار («اگه بهجای ۶ بذاریم ۴ چی؟») بعد از یک سوالِ شکلدار:
|
||||
یادآوریِ نرم (نه «این سوال شکل دارد») و بخشهای کاتالوگِ همان سوالِ قبلی. نرم است چون
|
||||
«مرسی» بعد از یک سوالِ هندسه نباید شکل بگیرد.
|
||||
"""
|
||||
if not previous or not (question or '').strip():
|
||||
return ''
|
||||
parts = [section for pattern, section in SECTIONS if pattern.search(previous)]
|
||||
if not parts:
|
||||
return ''
|
||||
return '\n'.join([FOLLOW_UP_HINT, _HEAD, *parts])
|
||||
|
||||
|
||||
def hint_for(question: str) -> str:
|
||||
"""یادآوری و فقط آن بخشهایی از کاتالوگ که به همین سوال میخورند؛ سوالِ بیشکل → ''."""
|
||||
text = question or ''
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user