nex_math/backend/services/ai_teacher.py

31 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""AI 教师:基于题目讲解与知识点状态生成即时反馈。
当前为本地规则式实现,不依赖外部模型:能够给出“为什么对/为什么错”的
讲解与后续建议;若配置了 OPENAI_API_KEY,可在此基础上扩展为真实模型调用。
"""
from __future__ import annotations
from models import Question, UserKnowledge
from services.mastery_engine import action_for
def explain(
question: Question,
selected: int,
correct: bool,
knowledge: UserKnowledge | None,
) -> str:
head = "回答正确。" if correct else "回答错误。"
base = question.explanation or "结合定义与图像性质重新判断。"
mastery_hint = ""
if knowledge is not None:
mastery_hint = (
f" 该知识点当前掌握度为 {knowledge.mastery}%,"
f"建议{action_for(knowledge.mastery)}。"
)
if correct:
return f"{head} 考点「{question.knowledge_name}」:{base}{mastery_hint}"
return f"{head} 你选择了选项 {chr(65 + selected)}。正确思路:{base}{mastery_hint}"