forked from hangshuo652/aurak
fix: skip content check when bank questions available, early generator return
This commit is contained in:
@@ -585,15 +585,20 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
|
|||||||
perQuestionTimeLimit: template?.perQuestionTimeLimit || 300,
|
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) {
|
if (!hasBankQuestions) {
|
||||||
this.logger.error(
|
const content = await this.getSessionContent(sessionData);
|
||||||
`[startSession] Insufficient content length: ${content?.length || 0}`,
|
|
||||||
);
|
if (!content || content.trim().length < 10) {
|
||||||
throw new BadRequestException(
|
this.logger.error(
|
||||||
'Selected knowledge source has no sufficient content for evaluation.',
|
`[startSession] Insufficient content length: ${content?.length || 0}`,
|
||||||
);
|
);
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Selected knowledge source has no sufficient content for evaluation.',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = this.sessionRepository.create(
|
const session = this.sessionRepository.create(
|
||||||
@@ -634,12 +639,14 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const model = await this.getModel(session.tenantId);
|
const model = await this.getModel(session.tenantId);
|
||||||
const content = await this.getSessionContent(session);
|
|
||||||
|
|
||||||
// Check if questions already exist in session (from question bank)
|
// Check if questions already exist in session (from question bank)
|
||||||
const existingQuestions = session.questions_json || [];
|
const existingQuestions = session.questions_json || [];
|
||||||
const hasExistingQuestions = existingQuestions.length > 0;
|
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
|
// Check if we already have state
|
||||||
const existingState = await this.graph.getState({
|
const existingState = await this.graph.getState({
|
||||||
configurable: { thread_id: sessionId },
|
configurable: { thread_id: sessionId },
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ export const questionGeneratorNode = async (
|
|||||||
targetCount: limitCount,
|
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) {
|
if (!model || !knowledgeBaseContent) {
|
||||||
console.error('[GeneratorNode] Missing model or knowledgeBaseContent');
|
console.error('[GeneratorNode] Missing model or knowledgeBaseContent');
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -78,13 +86,6 @@ export const questionGeneratorNode = async (
|
|||||||
.map((r, i) => `${i + 1}. ${r}`)
|
.map((r, i) => `${i + 1}. ${r}`)
|
||||||
.join('\n');
|
.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
|
const existingQuestionsText = existingQuestions
|
||||||
.map((q, i) => `Q${i + 1}: ${q.questionText}`)
|
.map((q, i) => `Q${i + 1}: ${q.questionText}`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user