Fix critical confusion detection bug
- Enhanced confusion detection to catch 'verstehe den zusammenhang nicht', 'das erklärt nicht', etc. - Reordered logic to prioritize confusion/help requests over other classifications - Added topic-aware fallback explanations for water/wetness questions - Fixed chat mode to properly handle mid-conversation confusion - Removed duplicate confusion handling logic This resolves the issue where children expressing confusion were stuck in endless Socratic questioning loops instead of getting explanations they needed.
This commit is contained in:
@@ -439,6 +439,9 @@ class KidsAIExplorer {
|
||||
answerLower.includes('versteh das nicht') || answerLower.includes('verstehe es nicht') ||
|
||||
answerLower.includes('ich verstehe nicht warum') || answerLower.includes("i don't understand why") ||
|
||||
answerLower.includes('aber ich verstehe nicht') || answerLower.includes("but i don't understand") ||
|
||||
answerLower.includes('verstehe den zusammenhang nicht') || answerLower.includes("don't understand the connection") ||
|
||||
answerLower.includes('das erklärt nicht') || answerLower.includes("that doesn't explain") ||
|
||||
answerLower.includes('das beantwortet nicht') || answerLower.includes("that doesn't answer") ||
|
||||
answerLower.includes('fällt mir nicht ein') || answerLower.includes("can't think of") ||
|
||||
answerLower.includes('mehr fällt mir nicht ein') || isAskingForHelp;
|
||||
|
||||
@@ -633,6 +636,9 @@ class KidsAIExplorer {
|
||||
answerLower.includes('versteh das nicht') || answerLower.includes('verstehe es nicht') ||
|
||||
answerLower.includes('ich verstehe nicht warum') || answerLower.includes("i don't understand why") ||
|
||||
answerLower.includes('aber ich verstehe nicht') || answerLower.includes("but i don't understand") ||
|
||||
answerLower.includes('verstehe den zusammenhang nicht') || answerLower.includes("don't understand the connection") ||
|
||||
answerLower.includes('das erklärt nicht') || answerLower.includes("that doesn't explain") ||
|
||||
answerLower.includes('das beantwortet nicht') || answerLower.includes("that doesn't answer") ||
|
||||
answerLower.includes('fällt mir nicht ein') || answerLower.includes("can't think of") ||
|
||||
answerLower.includes('mehr fällt mir nicht ein') || isAskingForHelp;
|
||||
|
||||
@@ -645,7 +651,7 @@ class KidsAIExplorer {
|
||||
);
|
||||
|
||||
// Pure "don't know" without additional thinking
|
||||
const isPureDontKnow = (hasDontKnowPhrase || isOnlyWhyQuestion || answer.trim().length < 5) && !hasSubstantialThinking && !isExpressingConfusion && !isAskingForHelp;
|
||||
const isPureDontKnow = (hasDontKnowPhrase || isOnlyWhyQuestion || answer.trim().length < 5) && !hasSubstantialThinking;
|
||||
|
||||
// Check if child is asking for a definition or explanation
|
||||
const isAskingForDefinition = answerLower.startsWith('was ist') || answerLower.startsWith('what is') ||
|
||||
@@ -655,25 +661,7 @@ class KidsAIExplorer {
|
||||
|
||||
let response;
|
||||
|
||||
if (isNegative || isPureDontKnow) {
|
||||
// For pure "no" or "don't know" answers without thinking, get Socratic guidance questions
|
||||
console.log('📤 Sending guidance request to /api/ask for Socratic questioning');
|
||||
|
||||
const guidancePrompt = this.currentLanguage === 'de'
|
||||
? `Ein Kind hat "${answer}" geantwortet auf die Frage "${currentQuestion}" über das Thema "${originalQuestion}". Das Kind weiß die Antwort nicht und braucht einfachere Grundlagen. Gib KEINE weiteren abstrakten Fragen! Stattdessen: 1) Beschreibe eine einfache Beobachtung, die das Kind machen kann (z.B. "Hast du schon mal Licht durch ein Glas Wasser gesehen?") 2) Lade zum praktischen Ausprobieren ein 3) Baue auf dem auf, was das Kind bereits kennt. Verwende konkrete, sichtbare Beispiele statt abstrakter Konzepte.`
|
||||
: `A child answered "${answer}" to the question "${currentQuestion}" about the topic "${originalQuestion}". The child doesn't know and needs simpler foundations. Give NO more abstract questions! Instead: 1) Describe a simple observation the child can make (e.g. "Have you ever seen light through a glass of water?") 2) Invite practical experimentation 3) Build on what the child already knows. Use concrete, visible examples instead of abstract concepts.`;
|
||||
|
||||
response = await fetch('/api/ask', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
question: guidancePrompt,
|
||||
language: this.currentLanguage
|
||||
})
|
||||
});
|
||||
} else if (isExpressingConfusion || isAskingForHelp) {
|
||||
if (isExpressingConfusion || isAskingForHelp) {
|
||||
// Child is expressing confusion or asking for help - provide a simple explanation
|
||||
console.log('📤 Sending explanation request for confused child or help request');
|
||||
|
||||
@@ -715,6 +703,24 @@ class KidsAIExplorer {
|
||||
: 'The child is asking for a definition. Provide a clear, child-friendly definition of the term. Use simple language and examples the child would know. Invite the child to ask more questions or explore the concept.'
|
||||
})
|
||||
});
|
||||
} else if (isNegative || isPureDontKnow) {
|
||||
// For pure "no" or "don't know" answers without thinking, get Socratic guidance questions
|
||||
console.log('📤 Sending guidance request to /api/ask for Socratic questioning');
|
||||
|
||||
const guidancePrompt = this.currentLanguage === 'de'
|
||||
? `Ein Kind hat "${answer}" geantwortet auf die Frage "${currentQuestion}" über das Thema "${originalQuestion}". Das Kind weiß die Antwort nicht und braucht einfachere Grundlagen. Gib KEINE weiteren abstrakten Fragen! Stattdessen: 1) Beschreibe eine einfache Beobachtung, die das Kind machen kann (z.B. "Hast du schon mal Licht durch ein Glas Wasser gesehen?") 2) Lade zum praktischen Ausprobieren ein 3) Baue auf dem auf, was das Kind bereits kennt. Verwende konkrete, sichtbare Beispiele statt abstrakter Konzepte.`
|
||||
: `A child answered "${answer}" to the question "${currentQuestion}" about the topic "${originalQuestion}". The child doesn't know and needs simpler foundations. Give NO more abstract questions! Instead: 1) Describe a simple observation the child can make (e.g. "Have you ever seen light through a glass of water?") 2) Invite practical experimentation 3) Build on what the child already knows. Use concrete, visible examples instead of abstract concepts.`;
|
||||
|
||||
response = await fetch('/api/ask', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
question: guidancePrompt,
|
||||
language: this.currentLanguage
|
||||
})
|
||||
});
|
||||
} else {
|
||||
// For substantial answers, acknowledge and validate
|
||||
console.log('📤 Sending validation request to /api/respond-to-answer');
|
||||
|
||||
@@ -598,9 +598,25 @@ The child is expressing confusion and needs help understanding. Provide a clear,
|
||||
|
||||
// Fallback for confusion explanations
|
||||
const isGerman = language === 'de';
|
||||
const confusionFallback = isGerman ?
|
||||
'Das passiert, weil Sonnenlicht aus vielen verschiedenen Farben besteht! Wenn Licht durch Regentropfen geht, werden diese Farben getrennt - wie bei einem Prisma. Du kannst das selbst ausprobieren: Halte ein Glas Wasser ins Sonnenlicht und schau, welche Farben entstehen! 🌈' :
|
||||
'This happens because sunlight is made of many different colors! When light goes through raindrops, these colors get separated - just like with a prism. You can try this yourself: hold a glass of water in sunlight and see what colors appear! 🌈';
|
||||
const { originalTopic } = req.body;
|
||||
|
||||
// Try to provide topic-specific fallback explanations
|
||||
let confusionFallback;
|
||||
const topicLower = (originalTopic || question || '').toLowerCase();
|
||||
|
||||
if (topicLower.includes('wasser') || topicLower.includes('water') || topicLower.includes('nass') || topicLower.includes('wet')) {
|
||||
confusionFallback = isGerman ?
|
||||
'Wasser ist "nass", weil es eine Flüssigkeit ist, die an anderen Oberflächen haftet und sie benetzt. Wenn Wassermoleküle auf deine Haut oder andere Materialien treffen, bleiben sie dort haften und fühlen sich feucht an. Das ist das Gefühl, das wir "nass" nennen! Du kannst das ausprobieren: Tropfe etwas Wasser auf verschiedene Materialien und schau, wie es sich verhält. 💧' :
|
||||
'Water is "wet" because it\'s a liquid that sticks to other surfaces and makes them moist. When water molecules touch your skin or other materials, they stay there and feel damp. That\'s the feeling we call "wet"! You can try this: drop some water on different materials and see how it behaves. 💧';
|
||||
} else if (topicLower.includes('regenbogen') || topicLower.includes('rainbow') || topicLower.includes('farben') || topicLower.includes('colors')) {
|
||||
confusionFallback = isGerman ?
|
||||
'Das passiert, weil Sonnenlicht aus vielen verschiedenen Farben besteht! Wenn Licht durch Regentropfen geht, werden diese Farben getrennt - wie bei einem Prisma. Du kannst das selbst ausprobieren: Halte ein Glas Wasser ins Sonnenlicht und schau, welche Farben entstehen! 🌈' :
|
||||
'This happens because sunlight is made of many different colors! When light goes through raindrops, these colors get separated - just like with a prism. You can try this yourself: hold a glass of water in sunlight and see what colors appear! 🌈';
|
||||
} else {
|
||||
confusionFallback = isGerman ?
|
||||
'Das ist eine sehr gute Frage! Manchmal sind Dinge komplizierter, als sie auf den ersten Blick scheinen. Lass mich dir das einfacher erklären: Alles hat bestimmte Eigenschaften, die wir mit unseren Sinnen wahrnehmen können. Was du fragst, hat mit diesen grundlegenden Eigenschaften zu tun. Hast du noch spezielle Fragen dazu? 🤔' :
|
||||
'That\'s a very good question! Sometimes things are more complicated than they seem at first. Let me explain this more simply: Everything has certain properties that we can perceive with our senses. What you\'re asking about relates to these basic properties. Do you have any specific questions about it? 🤔';
|
||||
}
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user