From 6e569ff4786f017b9e26241dad2ce73fd1f4bc3b Mon Sep 17 00:00:00 2001 From: Developer Date: Sat, 23 May 2026 22:32:51 +0800 Subject: [PATCH] fix: skip content check when bank questions available, early generator return --- server/src/assessment/assessment.service.ts | 25 ++++++++++++------- .../assessment/graph/nodes/generator.node.ts | 15 +++++------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/server/src/assessment/assessment.service.ts b/server/src/assessment/assessment.service.ts index f91e4db..ef24d2f 100644 --- a/server/src/assessment/assessment.service.ts +++ b/server/src/assessment/assessment.service.ts @@ -585,15 +585,20 @@ private async getModel(tenantId: string): Promise { perQuestionTimeLimit: template?.perQuestionTimeLimit || 300, }; - const content = await this.getSessionContent(sessionData); + // Skip content check if questions are loaded from the question bank + const hasBankQuestions = questionsFromBank.length > 0; - if (!content || content.trim().length < 10) { - this.logger.error( - `[startSession] Insufficient content length: ${content?.length || 0}`, - ); - throw new BadRequestException( - 'Selected knowledge source has no sufficient content for evaluation.', - ); + if (!hasBankQuestions) { + const content = await this.getSessionContent(sessionData); + + if (!content || content.trim().length < 10) { + this.logger.error( + `[startSession] Insufficient content length: ${content?.length || 0}`, + ); + throw new BadRequestException( + 'Selected knowledge source has no sufficient content for evaluation.', + ); + } } const session = this.sessionRepository.create( @@ -634,12 +639,14 @@ private async getModel(tenantId: string): Promise { } const model = await this.getModel(session.tenantId); - const content = await this.getSessionContent(session); // Check if questions already exist in session (from question bank) const existingQuestions = session.questions_json || []; const hasExistingQuestions = existingQuestions.length > 0; + // Skip content retrieval when bank questions exist (prevents generator errors) + const content = hasExistingQuestions ? '' : await this.getSessionContent(session); + // Check if we already have state const existingState = await this.graph.getState({ configurable: { thread_id: sessionId }, diff --git a/server/src/assessment/graph/nodes/generator.node.ts b/server/src/assessment/graph/nodes/generator.node.ts index b8ed09e..5af373d 100644 --- a/server/src/assessment/graph/nodes/generator.node.ts +++ b/server/src/assessment/graph/nodes/generator.node.ts @@ -22,6 +22,14 @@ export const questionGeneratorNode = async ( targetCount: limitCount, }); + const existingQuestions = state.questions || []; + + // Early return if enough questions from bank (no LLM call needed) + if (existingQuestions.length >= limitCount) { + console.log('[GeneratorNode] Skipping generation - enough questions from bank:', existingQuestions.length); + return { questions: existingQuestions }; + } + if (!model || !knowledgeBaseContent) { console.error('[GeneratorNode] Missing model or knowledgeBaseContent'); throw new Error( @@ -78,13 +86,6 @@ export const questionGeneratorNode = async ( .map((r, i) => `${i + 1}. ${r}`) .join('\n'); - const existingQuestions = state.questions || []; - - if (existingQuestions.length >= limitCount) { - console.log('[GeneratorNode] Skipping generation - enough questions from bank:', existingQuestions.length); - return { questions: existingQuestions }; - } - const existingQuestionsText = existingQuestions .map((q, i) => `Q${i + 1}: ${q.questionText}`) .join('\n');