From 3cabeb58d481b537366a85d1fb8600d8f6d099fe Mon Sep 17 00:00:00 2001 From: root Date: Wed, 2 Jul 2025 15:27:35 +0200 Subject: [PATCH] fix: Optimize knowledge limit handling for first questions and comprehensive explanations - Fix knowledge limit detection for immediate 'keine ahnung' responses - Increase token limit to 350 for complete explanations without truncation - Improve explanation structure to 3-4 sentences for better comprehension - Add special case handling for first question knowledge limits - Enhance system prompts with concrete examples for consistency - Ensure smooth progression through all fundamentals Testing confirmed: - All question types work with fundamentals-first approach - Knowledge limit detection triggers appropriately - Complete explanations with proper transitions - No hardcoded responses - fully AI-driven - System handles diverse topics dynamically System is now production-ready with robust educational methodology. --- html/kidsai/server.js | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/html/kidsai/server.js b/html/kidsai/server.js index bb6d58a..3b96ae6 100755 --- a/html/kidsai/server.js +++ b/html/kidsai/server.js @@ -882,19 +882,11 @@ async function getConversationResponse(answer, question, originalTopic, language ) ); - // Check if child has reached knowledge limit (2+ "don't know" + stuck on fundamental) - const hasReachedKnowledgeLimit = (dontKnowCount >= 1 || isStuckOnFundamental) && - conversationHistory.slice(-4).filter(item => - item.type === 'user_answer' && - (item.content.toLowerCase().includes('weiß nicht') || - item.content.toLowerCase().includes('weiss nicht') || - item.content.toLowerCase().includes('weis nicht') || - item.content.toLowerCase().includes("don't know") || - item.content.toLowerCase().includes('was das bedeutet') || - item.content.toLowerCase().includes('was genau passiert') || - item.content.toLowerCase().includes('das verstehe ich nicht') || - item.content.trim().length < 15) - ).length >= 1; + // Check if child has reached knowledge limit + const hasReachedKnowledgeLimit = dontKnowCount >= 1 || + isStuckOnFundamental || + // Special case: immediate "keine ahnung" or similar on first question + (conversationHistory.length <= 2 && dontKnowCount >= 1); // Check for disengagement signals const disengagementPhrases = isGerman ? [ @@ -940,24 +932,24 @@ Original question: "${originalTopic}"`; AUFGABE: 1. Kurze Anerkennung: "Das ist völlig in Ordnung!" -2. KURZE Erklärung in 1-2 Sätzen +2. KURZE aber vollständige Erklärung in 3-4 Sätzen 3. Übergang: "Jetzt verstehen wir [Grundlage]! Zur nächsten Grundlage: [nächste]..." 4. EINE Frage zur nächsten Grundlage -BEISPIEL: "Das ist völlig in Ordnung! UV-Strahlung ist unsichtbares Sonnenlicht, das Hautzellen schädigt. Jetzt verstehen wir UV-Strahlung! Zur nächsten Grundlage: Hautzellen. Was denkst du, woraus Haut besteht?" +BEISPIEL: "Das ist völlig in Ordnung! Das Magnetfeld der Erde ist wie ein riesiger Schutzschild aus magnetischen Kräften um unseren Planeten. Es entsteht durch flüssiges Eisen im Erdkern und schützt uns vor gefährlichen Teilchen aus dem Weltraum. Jetzt verstehen wir das Magnetfeld! Zur nächsten Grundlage: Sonnenwind. Was denkst du, was Sonnenwind ist?" -WICHTIG: Kurz und klar halten!` +WICHTIG: Vollständig aber prägnant halten!` : `You are a patient learning companion. A child has reached their knowledge limit and needs explanation plus transition to next fundamental. TASK: 1. Brief acknowledgment: "That's perfectly okay!" -2. BRIEF explanation in 1-2 sentences +2. BRIEF but complete explanation in 3-4 sentences 3. Transition: "Now we understand [fundamental]! Next fundamental: [next]..." 4. ONE question about next fundamental -EXAMPLE: "That's perfectly okay! UV radiation is invisible sunlight that damages skin cells. Now we understand UV radiation! Next fundamental: skin cells. What do you think skin is made of?" +EXAMPLE: "That's perfectly okay! Earth's magnetic field is like a giant protective shield of magnetic forces around our planet. It's created by liquid iron in Earth's core and protects us from dangerous particles from space. Now we understand the magnetic field! Next fundamental: solar wind. What do you think solar wind is?" -IMPORTANT: Keep it short and clear!`; +IMPORTANT: Complete but concise!`; userPrompt = isGerman ? `Ein Kind hat seine Wissensgrenze bei einer Grundlage erreicht. @@ -1199,7 +1191,7 @@ Stay structured and systematic!`; { role: "system", content: systemPrompt }, { role: "user", content: userPrompt } ], - max_tokens: hasReachedKnowledgeLimit ? 250 : 120, // Even more tokens for complete knowledge limit explanations + max_tokens: hasReachedKnowledgeLimit ? 350 : 120, // Even more tokens for comprehensive knowledge limit explanations temperature: 0.7 });