| """Append optional learner-facing context to system prompts for interactive Q&A.""" | |
| import json | |
| from typing import Any | |
| def with_learner_context(system: str, learner_context: str | None) -> str: | |
| if not learner_context or not learner_context.strip(): | |
| return system | |
| return ( | |
| system | |
| + "\n\n---\nLearner context (use naturally; do not fabricate facts):\n" | |
| + learner_context.strip() | |
| ) | |
| def with_draft_snapshot(system: str, draft_snapshot: dict[str, Any] | None) -> str: | |
| if not draft_snapshot: | |
| return system | |
| cleaned = {k: v for k, v in draft_snapshot.items() if not str(k).startswith("_")} | |
| if not cleaned: | |
| return system | |
| return ( | |
| system | |
| + "\n\n---\nCurrent form draft from the client (carry forward and update cumulatively in draft_update every turn):\n" | |
| + json.dumps(cleaned, ensure_ascii=False) | |
| ) | |