|
|
@@ -33,7 +33,11 @@ export const questionGeneratorNode = async (
|
|
|
const style = state.style || 'technical';
|
|
|
const difficultyText = state.difficultyDistribution
|
|
|
? JSON.stringify(state.difficultyDistribution)
|
|
|
- : '随机分布 (Random distribution)';
|
|
|
+ : isZh
|
|
|
+ ? '随机分布'
|
|
|
+ : isJa
|
|
|
+ ? 'ランダム分布'
|
|
|
+ : 'Random distribution';
|
|
|
const keywords = state.keywords || [];
|
|
|
const hasKeywords = keywords.length > 0;
|
|
|
const keywordText = hasKeywords ? keywords.join(', ') : '';
|
|
|
@@ -79,6 +83,9 @@ export const questionGeneratorNode = async (
|
|
|
|
|
|
const systemPromptZh = `你是一位专业的知识评估专家。请根据提供的知识库片段生成 1 个唯一的测试题目。
|
|
|
|
|
|
+### 强制性语言规则:
|
|
|
+**必须使用中文 (Simplified Chinese) 进行回复**。即使知识库内容是英文或其他语言,问题(question_text)和关键点(key_points)也必须使用中文。
|
|
|
+
|
|
|
### 强制性多样性规则:
|
|
|
${rulesZh}
|
|
|
|
|
|
@@ -101,16 +108,34 @@ ${hasKeywords ? `目标关键词:${keywordText}\n` : ''}出题风格:${style
|
|
|
|
|
|
const systemPromptJa = `あなたは専門的なアセスメントエキスパートです。提供されたナレッジベースに基づいて、ユニークな問題を 1 つ作成してください。
|
|
|
|
|
|
+### 言語ルール(最重要):
|
|
|
+**必ず日本語で作成してください**。提供されたナレッジベースが英語や中国語、その他の言語であっても、質問文(question_text)およびキーポイント(key_points)は必ず日本語で回答してください。中国語が混ざらないように厳格に注意してください。
|
|
|
+
|
|
|
### 多様性ルール:
|
|
|
${rulesJa}
|
|
|
|
|
|
### 作成済み問題リスト:
|
|
|
${existingQuestionsText || 'なし'}
|
|
|
|
|
|
-JSON 形式で 1 つ返してください。`;
|
|
|
+### 任務:
|
|
|
+${hasKeywords ? `目標キーワード:${keywordText}\n` : ''}出題スタイル:${style}
|
|
|
+難易度:${difficultyText}
|
|
|
+
|
|
|
+以下のJSON配列形式で問題を1つ返してください:
|
|
|
+[
|
|
|
+ {
|
|
|
+ "question_text": "...",
|
|
|
+ "key_points": ["ポイント1", "ポイント2"],
|
|
|
+ "difficulty": "...",
|
|
|
+ "basis": "[n] 引用箇所..."
|
|
|
+ }
|
|
|
+]`;
|
|
|
|
|
|
const systemPromptEn = `You are an expert examiner. Generate 1 UNIQUE question based on the provided context.
|
|
|
|
|
|
+### Language Rule:
|
|
|
+**You MUST generate the question and key points in English.**
|
|
|
+
|
|
|
### Diversity Rules:
|
|
|
${rulesEn}
|
|
|
|
|
|
@@ -125,10 +150,10 @@ Return 1 question as a JSON array.`;
|
|
|
? systemPromptJa
|
|
|
: systemPromptEn;
|
|
|
const humanMsg = isZh
|
|
|
- ? `基于以下内容生成题目:\n\n${knowledgeBaseContent}`
|
|
|
+ ? `请使用中文基于以下内容生成题目:\n\n${knowledgeBaseContent}`
|
|
|
: isJa
|
|
|
- ? `以下の内容に基づいて作成してください:\n\n${knowledgeBaseContent}`
|
|
|
- : `Generate question based on:\n\n${knowledgeBaseContent}`;
|
|
|
+ ? `以下の内容に基づいて、必ず日本語でアセスメント問題を作成してください:\n\n${knowledgeBaseContent}`
|
|
|
+ : `Generate evaluation question in English based on:\n\n${knowledgeBaseContent}`;
|
|
|
|
|
|
try {
|
|
|
const response = await model.invoke([
|
|
|
@@ -137,10 +162,17 @@ Return 1 question as a JSON array.`;
|
|
|
]);
|
|
|
|
|
|
try {
|
|
|
- const newQuestions = safeParseJson(response.content as string);
|
|
|
- if (!newQuestions || !Array.isArray(newQuestions)) {
|
|
|
+ let newQuestions = safeParseJson<any>(response.content as string);
|
|
|
+
|
|
|
+ if (!newQuestions) {
|
|
|
+ console.error('[GeneratorNode] Failed to parse JSON. Raw content:', response.content);
|
|
|
throw new Error('Invalid JSON format from AI');
|
|
|
}
|
|
|
+
|
|
|
+ // Handle both array and single object
|
|
|
+ if (!Array.isArray(newQuestions)) {
|
|
|
+ newQuestions = [newQuestions];
|
|
|
+ }
|
|
|
const mappedNewQuestions = newQuestions.map((q: any) => ({
|
|
|
id: (existingQuestions.length + 1).toString(),
|
|
|
questionText: q.question_text,
|