fix: shuffle choice options per session + clean followup hints

- Options shuffled with correctAnswer remapped at session creation
- Followup hints strip conditional prefix (如果只说了XX,追问:)
This commit is contained in:
Developer
2026-05-21 12:42:52 +08:00
parent 734c0129d8
commit 24ffc028e2
2 changed files with 31 additions and 13 deletions
+29 -12
View File
@@ -505,18 +505,35 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
targetCount,
);
questionsFromBank = selectedItems.map(item => ({
id: item.id,
questionText: item.questionText,
questionType: item.questionType,
options: item.options,
correctAnswer: item.correctAnswer,
judgment: item.judgment,
keyPoints: item.keyPoints,
difficulty: item.difficulty,
dimension: item.dimension,
basis: item.basis,
}));
questionsFromBank = selectedItems.map(item => {
let options = item.options;
let correctAnswer = item.correctAnswer;
if (item.questionType === 'MULTIPLE_CHOICE' && options && options.length > 0 && correctAnswer) {
const labels = ['A', 'B', 'C', 'D'];
const optTexts = options.map((o: string) => o.replace(/^[A-D][.)、]\s*/, ''));
const correctIdx = correctAnswer.charCodeAt(0) - 65;
const correctText = correctIdx >= 0 && correctIdx < optTexts.length ? optTexts[correctIdx] : null;
const indices = optTexts.map((_: any, i: number) => i);
for (let i = indices.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[indices[i], indices[j]] = [indices[j], indices[i]];
}
options = indices.map((origIdx: number, newPos: number) => `${labels[newPos]}${optTexts[origIdx]}`);
correctAnswer = correctText ? labels[indices.indexOf(correctIdx)] : correctAnswer;
}
return {
id: item.id,
questionText: item.questionText,
questionType: item.questionType,
options,
correctAnswer,
judgment: item.judgment,
keyPoints: item.keyPoints,
difficulty: item.difficulty,
dimension: item.dimension,
basis: item.basis,
};
});
const answerKey: Record<string, { correctAnswer?: string | null; judgment?: string | null; followupHints?: string[] | null }> = {};
selectedItems.forEach(item => {
@@ -254,7 +254,8 @@ Format your response as JSON:
let followupHintMsg: AIMessage | null = null;
if (shouldFollowUp && followupHints.length > 0) {
const hint = followupHints[Math.min(currentFollowUpCount, followupHints.length - 1)];
let hint = followupHints[Math.min(currentFollowUpCount, followupHints.length - 1)];
hint = hint.replace(/^如果[^,]*[,]\s*追问[:]\s*/i, '').replace(/^如果[^。]*[。]\s*/i, '');
const hintLabel = isZh
? `让我帮你完善一下:${hint}`
: isJa