fix: shuffle bank questions + grader LLM error resilience
- selectQuestions: shuffle final result for random question order - grader: wrap LLM invoke in try-catch, default score 5 on failure - grader: inner try-catch for JSON parse errors, graceful fallback
This commit is contained in:
@@ -201,6 +201,7 @@ Format your response as JSON:
|
||||
console.log('[GraderNode] Question:', currentQuestion?.questionText?.substring(0, 100));
|
||||
console.log('[GraderNode] Target dimension:', currentQuestion?.dimension);
|
||||
|
||||
try {
|
||||
const response = await model.invoke([
|
||||
new SystemMessage(systemPrompt),
|
||||
new HumanMessage(userContentText),
|
||||
@@ -279,14 +280,29 @@ Format your response as JSON:
|
||||
? currentQuestionIndex
|
||||
: currentQuestionIndex + 1,
|
||||
} as any;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse grade from AI response:', error);
|
||||
} catch (parseError) {
|
||||
console.error('[GraderNode] Failed to parse grade:', parseError);
|
||||
const scoreLabel = isZh ? '得分' : isJa ? 'スコア' : 'Score';
|
||||
const fallbackMsg = new AIMessage(`${scoreLabel}: 5/10\n\n评分解析失败,默认给5分。`);
|
||||
return {
|
||||
feedbackHistory: [
|
||||
new AIMessage("I had some trouble grading that, but let's move on."),
|
||||
],
|
||||
currentQuestionIndex: currentQuestionIndex + 1,
|
||||
feedbackHistory: [fallbackMsg],
|
||||
scores: { [currentQuestion.id || currentQuestionIndex.toString()]: 5 },
|
||||
shouldFollowUp: false,
|
||||
followUpCount: 0,
|
||||
currentQuestionIndex: currentQuestionIndex + 1,
|
||||
} as any;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[GraderNode] LLM grading failed:', error);
|
||||
const scoreLabel = isZh ? '得分' : isJa ? 'スコア' : 'Score';
|
||||
const feedbackLabel = isZh ? '反馈' : isJa ? 'フィードバック' : 'Feedback';
|
||||
const fallbackMsg = new AIMessage(`${scoreLabel}: 5/10\n\n${feedbackLabel}: 评分服务暂时不可用,默认给5分。`);
|
||||
return {
|
||||
feedbackHistory: [fallbackMsg],
|
||||
scores: { [currentQuestion.id || currentQuestionIndex.toString()]: 5 },
|
||||
shouldFollowUp: false,
|
||||
followUpCount: 0,
|
||||
currentQuestionIndex: currentQuestionIndex + 1,
|
||||
} as any;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -588,7 +588,7 @@ export class QuestionBankService {
|
||||
this.logger.log(
|
||||
`[selectQuestions] Selected ${selected.length} questions from bank ${bankId}`,
|
||||
);
|
||||
return selected;
|
||||
return this.shuffleArray(selected);
|
||||
}
|
||||
|
||||
async batchReviewItems(
|
||||
|
||||
Reference in New Issue
Block a user