feat(exam_pkg): 优化出题系统稳定性与推理模型适配

- core/llm_utils: MiMo模型自动注入thinking=disabled参数,全局生效
- config: 新增LLM_DISABLE_THINKING配置项(默认true)
- generator: 推理模型自适应max_tokens(1.5x)、429限流重试+指数退避、v2管线补题机制
- generator: analyze_document_for_exam新增max_total参数控制AI出题上限
- generator: validate_questions_schema兼容type和question_type字段
- grader: 主观题max_tokens从1000提升至2000、fuzzy_match增加编辑距离容错
- manager: results变量初始化防NameError、透传max_total参数
- api: /exam/generate-smart支持max_total请求参数
This commit is contained in:
lacerate551
2026-06-22 18:51:11 +08:00
parent b966be5417
commit a31ee4bba0
8 changed files with 475 additions and 75 deletions

View File

@@ -246,6 +246,7 @@ def api_generate_smart():
"file_path": "public/产品手册.pdf",
"collection": "public_kb",
"difficulty": 3, // 可选,默认 3
"max_total": 20, // 可选AI出题总数上限。不传则不限制
"options": {} // 可选
}
@@ -267,6 +268,16 @@ def api_generate_smart():
if diff_error:
return error_response("INVALID_PARAMS", BAD_REQUEST, diff_error, http_status=400)
# 可选AI出题总数上限不传则不限制
max_total = data.get('max_total')
if max_total is not None:
try:
max_total = int(max_total)
if max_total <= 0:
return error_response("INVALID_PARAMS", BAD_REQUEST, "max_total 必须为正整数", http_status=400)
except (ValueError, TypeError):
return error_response("INVALID_PARAMS", BAD_REQUEST, "max_total 必须为整数", http_status=400)
# 校验排除题干列表(可选)
exclude_stems = data.get('exclude_stems')
stems_error = validate_exclude_stems(exclude_stems)
@@ -298,11 +309,11 @@ def api_generate_smart():
f"AI智能出题: {os.path.basename(file_path)}"
)
def _do_smart_generate(task, fp, coll, diff, opts, req_id, excl):
def _do_smart_generate(task, fp, coll, diff, opts, req_id, excl, max_t):
"""后台执行 AI 智能出题"""
registry.update_progress(task.id, stage='AI分析', message='正在分析文档内容...')
from exam_pkg.manager import analyze_file_for_exam
ai_analysis = analyze_file_for_exam(file_path=fp, collection=coll)
ai_analysis = analyze_file_for_exam(file_path=fp, collection=coll, max_total=max_t)
q_types = ai_analysis.get('question_types', {})
if not q_types or sum(q_types.values()) == 0:
@@ -325,7 +336,8 @@ def api_generate_smart():
task.id, _do_smart_generate,
file_path, collection,
data.get('difficulty', 3), data.get('options', {}),
data.get('request_id'), data.get('exclude_stems')
data.get('request_id'), data.get('exclude_stems'),
max_total
)
return success_response(