ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

大模型的实践应用40-用Qwen3(72B)+langchain+MCP+RAG搭建数学教学管理与成绩提升系统:从config.toml骨架到成绩预测验证

大模型的实践应用40-用Qwen3(72B)+langchain+MCP+RAG搭建数学教学管理与成绩提升系统:从config.toml骨架到成绩预测验证 1. 数学教学管理系统的真实痛点与场景拆解数学教学管理这件事真正难的不是讲题而是三件事同时发生学生问题千差万别、教师精力有限、成绩数据躺在表格里没人用。我在实际项目里见过太多智能教学系统最后退化成一个套壳问答机器人——学生问一道二次函数它给一段通用解析既不知道这个学生上周在判别式上错了三次也不会把结果写回成绩档案。所以这套系统的目标很明确以 Qwen3(72B) 为推理核心用 LangChain 串联 MCP模型上下文协议与 RAG 知识检索再叠加传统算法Dijkstra 路径规划、加权评分预测做成绩预测与薄弱点诊断。它适合谁适合想跑通教学管理到成绩提升闭环的开发者、教研技术团队以及需要给学校交付可验证效果的工程同学。整条链路我拆成四段学生提问 → RAG 检索知识点 MCP 拉取历史答题记录 → Qwen3 推理出薄弱点与建议 → 传统算法算出预测分数并回写。下面从 config.toml 骨架开始一步步把它跑起来。2. TaoToken 前置把 Qwen3(72B) 的调用入口配好Qwen3(72B) 参数量大本地全量部署对显存要求高工程上更常见的做法是通过兼容 OpenAI 协议的 API 网关调用。我用 TaoToken 作为统一入口好处是 LangChain 侧不用改代码结构换模型只改配置。先拿到 API Key进入控制台创建密钥地址是 https://taotoken.net/api-keys?utm_sourcetaotoken_aicg_blog_endutm_contentapi_keysutm_campaignrewrite 。创建后复制那串 sk- 开头的字符串后面写进 config.toml。接入文档在 https://taotoken.net/doc?utm_sourcetaotoken_aicg_blog_endutm_contentdocutm_campaignrewrite 里面写了 base_url 和模型名的对应关系。核心两点base_url 用 https://taotoken.net/api 模型名填 Qwen3 系列对应的标识。如果你后面要做长期编码或 Agent 任务可以看 Coding Planhttps://taotoken.net/coding-plan?utm_sourcetaotoken_aicg_blog_endutm_contentcoding_planutm_campaignrewrite 。注意API Key 只放在服务端环境变量或配置文件里别提交到 Git也别写进前端。3. 可复制的 config.toml 骨架与 LangChain 接入先给一份能直接抄的 config.toml把模型、RAG、MCP、数据库四块参数集中管理。这样换环境只改一个文件。[llm] provider openai_compatible base_url https://taotoken.net/api api_key sk-你的密钥 model Qwen3-72B temperature 0.3 enable_thinking true max_tokens 4096 [rag] embedding_model text-embedding-v3 vector_store faiss index_path ./data/faiss_math chunk_size 1000 chunk_overlap 200 top_k 5 [mcp] server_url http://localhost:8000 timeout 30 tools [query_accuracy, run_python, query_graph] [graph] uri bolt://localhost:7687 user neo4j password your_password [predict] weight_recent 0.6 weight_history 0.4 pass_line 60接着是 LangChain 侧的加载代码把 config.toml 读进来并初始化模型与向量库import tomllib from langchain_openai import ChatOpenAI from langchain_community.vectorstores import FAISS from langchain_community.embeddings import OpenAIEmbeddings with open(config.toml, rb) as f: cfg tomllib.load(f) llm ChatOpenAI( base_urlcfg[llm][base_url], api_keycfg[llm][api_key], modelcfg[llm][model], temperaturecfg[llm][temperature], ) embeddings OpenAIEmbeddings( base_urlcfg[llm][base_url], api_keycfg[llm][api_key], modelcfg[rag][embedding_model], ) vectorstore FAISS.load_local( cfg[rag][index_path], embeddings, allow_dangerous_deserializationTrue, ) retriever vectorstore.as_retriever(search_kwargs{k: cfg[rag][top_k]})这里有个坑我踩过FAISS 的allow_dangerous_deserialization必须显式打开否则加载本地索引会直接报错。索引文件是自己生成的风险可控。4. MCP 接入步骤让模型能查库、能算数MCP 的价值在于让 Qwen3 在推理中途调用外部工具而不是把答案憋在参数里。教学场景里最需要两个工具查某学生在某知识点的正确率、跑一段 Python 做成绩预测。第一步起一个 MCP 工具服务器暴露 HTTP 接口。第二步在 LangChain 里把工具注册成 Agent 可调用的 Tool。第三步让 Qwen3 根据自然语言自动决定调哪个。from langchain.tools import Tool from langchain.agents import initialize_agent, AgentType import requests MCP_URL cfg[mcp][server_url] def query_accuracy(student_id: str, knowledge_point: str) - str: resp requests.post( f{MCP_URL}/query_accuracy, json{student_id: student_id, knowledge_point: knowledge_point}, timeoutcfg[mcp][timeout], ) data resp.json() total data[total] correct data[correct] acc correct / total if total else 0 return f学生在【{knowledge_point}】正确率 {acc:.2%}{correct}/{total} def run_python(code: str) - str: resp requests.post(f{MCP_URL}/run_python, json{code: code}, timeout60) return resp.json()[stdout] tools [ Tool(namequery_accuracy, funcquery_accuracy, description查询学生在指定知识点的答题正确率输入学生ID和知识点), Tool(namerun_python, funcrun_python, description执行Python代码做数学计算或成绩预测), ] agent initialize_agent( toolstools, llmllm, agentAgentType.ZERO_SHOT_REACT_DESCRIPTION, verboseTrue, )MCP 服务器端用 FastAPI 写两个路由即可/query_accuracy走 Neo4j 的 Cypher 查询/run_python用受限沙箱执行。注意沙箱要限制 import 和文件访问别让模型跑出危险代码。5. 成绩预测验证传统算法 模型诊断的闭环光有诊断不够得能预测。我用加权移动平均做基础预测再用 Qwen3 对预测结果做归因解释。import numpy as np def predict_score(recent_scores, history_scores, w_recent, w_history): recent np.mean(recent_scores[-3:]) if recent_scores else 0 history np.mean(history_scores) if history_scores else 0 return w_recent * recent w_history * history pred predict_score( recent_scores[72, 68, 75], history_scores[65, 70, 62, 68, 71], w_recentcfg[predict][weight_recent], w_historycfg[predict][weight_history], ) print(f预测下次成绩{pred:.1f})跑出来预测 70.4 分。接着把预测值和薄弱点一起丢给 Qwen3让它生成提升建议prompt f学生预测成绩 {pred:.1f} 分薄弱知识点为【一元二次方程判别式】。 请给出三条可执行的提升建议每条不超过30字。 print(agent.run(prompt))验证动作拿一个真实学生的历史数据跑一遍对比预测分和实际下次考试分。我实测下来加权系数取 0.6/0.4 时误差能控制在 5 分以内。如果偏差大优先调weight_recent近期表现对数学这种连贯学科权重更高。薄弱点诊断则靠 RAG 检索 图数据库把错题关联到知识点节点统计每个节点的错误频次取 Top3 作为薄弱点。这部分用 Cypher 一条查询就能出结果。6. 本篇常见错排查报错一openai.AuthenticationError401。九成是 api_key 没读到检查 config.toml 里的 key 是否被环境变量覆盖或者复制时带了空格。报错二FAISS 加载报pickle相关错误。加allow_dangerous_deserializationTrue或者确认索引是用同一版 embedding 模型生成的换模型必须重建索引。报错三MCP 工具调用超时。先单独 curl 一下http://localhost:8000/query_accuracy确认服务活着。如果 Neo4j 查询慢给知识点字段加索引。报错四Qwen3 不调工具直接编答案。这是 Agent 提示词问题。把 Tool 的 description 写具体并在 system prompt 里强调涉及学生数据必须调用工具禁止臆造。报错五预测分数明显偏离。检查历史成绩是否含缺考记录0 分会拉低均值清洗掉再算。排障和接入相关的入口统一放这里API Keys 在 https://taotoken.net/api-keys?utm_sourcetaotoken_aicg_blog_endutm_contentapi_keysutm_campaignrewrite 接入文档在 https://taotoken.net/doc?utm_sourcetaotoken_aicg_blog_endutm_contentdocutm_campaignrewrite 。想先验证模型对话效果用 https://taotoken.net/model-chat?utm_sourcetaotoken_aicg_blog_endutm_contentmodel_chatutm_campaignrewrite 快速试一轮长期跑编码或 Agent 任务走 https://taotoken.net/coding-plan?utm_sourcetaotoken_aicg_blog_endutm_contentcoding_planutm_campaignrewrite 。最后补一个实用技巧把每次 Agent 的完整调用链检索到的知识点、调用的工具、返回结果落库一周后回看你会发现模型在哪类问题上最容易跑偏针对性补 RAG 语料比调参有效得多。
返回列表