fix: restore main runtime sources and cache consistency
This commit is contained in:
@@ -1032,6 +1032,7 @@ def analyze_document_for_exam(chunks: List[Dict], max_total: int = None) -> Dict
|
||||
)
|
||||
prompt += f"\n### {section_name[:30]}\n{content_preview[:300]}\n"
|
||||
|
||||
question_limit = min(total_knowledge_points * 2, max_total if max_total else 20)
|
||||
prompt += """
|
||||
## 要求
|
||||
根据文档内容特点,决定:
|
||||
@@ -1055,10 +1056,10 @@ def analyze_document_for_exam(chunks: List[Dict], max_total: int = None) -> Dict
|
||||
|
||||
注意:
|
||||
- 不适合的题型数量设为 0
|
||||
- 所有数量之和不要超过 {min(total_knowledge_points * 2, 20)}
|
||||
- 所有数量之和不要超过 %d
|
||||
- 必须返回合法 JSON,不要有其他内容
|
||||
|
||||
请直接输出 JSON:"""
|
||||
请直接输出 JSON:""" % question_limit
|
||||
|
||||
try:
|
||||
response = generator._call_llm(prompt)
|
||||
|
||||
@@ -219,6 +219,41 @@ def grade_fill_blank(answer: Dict) -> Dict:
|
||||
student_answers = answer.get('student_answer', [])
|
||||
max_score = answer.get('max_score', 4.0)
|
||||
|
||||
if not isinstance(student_answers, list):
|
||||
logger.warning(
|
||||
"填空题学生答案格式错误: 期望列表,实际为 %s",
|
||||
type(student_answers).__name__,
|
||||
)
|
||||
return {
|
||||
"question_id": answer.get('question_id'),
|
||||
"score": 0,
|
||||
"max_score": max_score,
|
||||
"grading_status": "failed",
|
||||
"details": {
|
||||
"error": f"学生答案格式错误,期望列表,实际为 {type(student_answers).__name__}"
|
||||
},
|
||||
}
|
||||
|
||||
for index, student_answer in enumerate(student_answers):
|
||||
if not isinstance(student_answer, str):
|
||||
logger.warning(
|
||||
"填空题学生答案第 %s 项格式错误: 期望字符串,实际为 %s",
|
||||
index + 1,
|
||||
type(student_answer).__name__,
|
||||
)
|
||||
return {
|
||||
"question_id": answer.get('question_id'),
|
||||
"score": 0,
|
||||
"max_score": max_score,
|
||||
"grading_status": "failed",
|
||||
"details": {
|
||||
"error": (
|
||||
f"填空题学生答案第 {index + 1} 项格式错误,期望字符串,"
|
||||
f"实际为 {type(student_answer).__name__}"
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
# 归一化答案格式(修复 LLM 生成的扁平数组问题)
|
||||
blank_count = question_content.get('data', {}).get('blank_count', 0)
|
||||
correct_answers = _normalize_fill_blank_answer(correct_answers, blank_count)
|
||||
|
||||
@@ -170,8 +170,9 @@ class ExamLocalDB:
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (exam_id, name, description, total_score, len(questions), duration, 'published', created_by))
|
||||
|
||||
# 关联题目
|
||||
for order, qid in enumerate(question_ids):
|
||||
# 仅关联实际存在的题目,避免无效 ID 触发外键约束。
|
||||
valid_question_ids = [q['id'] for q in questions]
|
||||
for order, qid in enumerate(valid_question_ids):
|
||||
cursor.execute('''
|
||||
INSERT INTO exam_questions (exam_id, question_id, question_order)
|
||||
VALUES (?, ?, ?)
|
||||
@@ -183,7 +184,7 @@ class ExamLocalDB:
|
||||
'total_score': total_score,
|
||||
'total_count': len(questions),
|
||||
'duration': duration,
|
||||
'question_ids': question_ids
|
||||
'question_ids': valid_question_ids
|
||||
}
|
||||
|
||||
def get_exam(self, exam_id: str) -> Optional[Dict]:
|
||||
|
||||
Reference in New Issue
Block a user