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:
@@ -505,18 +505,35 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
|
|||||||
targetCount,
|
targetCount,
|
||||||
);
|
);
|
||||||
|
|
||||||
questionsFromBank = selectedItems.map(item => ({
|
questionsFromBank = selectedItems.map(item => {
|
||||||
id: item.id,
|
let options = item.options;
|
||||||
questionText: item.questionText,
|
let correctAnswer = item.correctAnswer;
|
||||||
questionType: item.questionType,
|
if (item.questionType === 'MULTIPLE_CHOICE' && options && options.length > 0 && correctAnswer) {
|
||||||
options: item.options,
|
const labels = ['A', 'B', 'C', 'D'];
|
||||||
correctAnswer: item.correctAnswer,
|
const optTexts = options.map((o: string) => o.replace(/^[A-D][.)、]\s*/, ''));
|
||||||
judgment: item.judgment,
|
const correctIdx = correctAnswer.charCodeAt(0) - 65;
|
||||||
keyPoints: item.keyPoints,
|
const correctText = correctIdx >= 0 && correctIdx < optTexts.length ? optTexts[correctIdx] : null;
|
||||||
difficulty: item.difficulty,
|
const indices = optTexts.map((_: any, i: number) => i);
|
||||||
dimension: item.dimension,
|
for (let i = indices.length - 1; i > 0; i--) {
|
||||||
basis: item.basis,
|
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 }> = {};
|
const answerKey: Record<string, { correctAnswer?: string | null; judgment?: string | null; followupHints?: string[] | null }> = {};
|
||||||
selectedItems.forEach(item => {
|
selectedItems.forEach(item => {
|
||||||
|
|||||||
@@ -254,7 +254,8 @@ Format your response as JSON:
|
|||||||
|
|
||||||
let followupHintMsg: AIMessage | null = null;
|
let followupHintMsg: AIMessage | null = null;
|
||||||
if (shouldFollowUp && followupHints.length > 0) {
|
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
|
const hintLabel = isZh
|
||||||
? `让我帮你完善一下:${hint}`
|
? `让我帮你完善一下:${hint}`
|
||||||
: isJa
|
: isJa
|
||||||
|
|||||||
Reference in New Issue
Block a user