Add detection for 'was passiert' questions and light/water topic explanations

- Enhanced definition detection to include 'was passiert' and 'what happens' patterns
- Added topic-specific explanations for light through water/glass scenarios
- Updated both confusion and definition fallbacks for light refraction topics
- This should fix cases where children ask 'was passiert denn da?' and get explanations instead of more questions
This commit is contained in:
root
2025-06-30 16:44:29 +02:00
parent e361c2c5fb
commit 37effc0086
3 changed files with 50 additions and 19 deletions

View File

@@ -474,8 +474,16 @@ class KidsAIExplorer {
console.log(`🔢 Recent "don't know" count (Chat): ${recentDontKnowCountChat}`);
// If child has said "don't know" 2 or more times recently, they need help
const needsExplanationDueToRepeatedDontKnowChat = recentDontKnowCountChat >= 2;
// Check if child is asking a question but then says "don't know" - they need help
const isAskingQuestionThenDontKnow = conversationHistoryChat.length > 0 &&
conversationHistoryChat[conversationHistoryChat.length - 2] &&
conversationHistoryChat[conversationHistoryChat.length - 2].includes('?') &&
hasDontKnowPhrase;
console.log(`🔍 Is asking question then don't know: ${isAskingQuestionThenDontKnow}`);
// If child has said "don't know" 2 or more times recently, OR asked a question then said don't know, they need help
const needsExplanationDueToRepeatedDontKnowChat = recentDontKnowCountChat >= 2 || isAskingQuestionThenDontKnow;
let response;
@@ -698,8 +706,16 @@ class KidsAIExplorer {
console.log(`🔢 Recent "don't know" count: ${recentDontKnowCount}`);
// If child has said "don't know" 2 or more times recently, they need help
const needsExplanationDueToRepeatedDontKnow = recentDontKnowCount >= 2;
// Check if child is asking a question but then says "don't know" - they need help
const isAskingQuestionThenDontKnowStep = conversationHistory.length > 0 &&
conversationHistory[conversationHistory.length - 2] &&
conversationHistory[conversationHistory.length - 2].includes('?') &&
hasDontKnowPhrase;
console.log(`🔍 Is asking question then don't know (Step): ${isAskingQuestionThenDontKnowStep}`);
// If child has said "don't know" 2 or more times recently, OR asked a question then said don't know, they need help
const needsExplanationDueToRepeatedDontKnow = recentDontKnowCount >= 2 || isAskingQuestionThenDontKnowStep;
// Check if child is asking for a definition or explanation
const isAskingForDefinition = answerLower.startsWith('was ist') || answerLower.startsWith('what is') ||
@@ -710,6 +726,8 @@ class KidsAIExplorer {
answerLower.includes('wo sind') || answerLower.includes('where are') ||
answerLower.includes('wie funktioniert') || answerLower.includes('how does') ||
answerLower.includes('warum ist') || answerLower.includes('why is') ||
answerLower.includes('was passiert') || answerLower.includes('what happens') ||
answerLower.includes('was geschieht') || answerLower.includes('what occurs') ||
(answerLower.includes('?') && (answerLower.includes('ist ein') || answerLower.includes('is a')));
let response;

View File

@@ -622,7 +622,13 @@ The child is expressing confusion and needs help understanding. Provide a clear,
let confusionFallback;
const topicLower = (originalTopic || question || '').toLowerCase();
if (topicLower.includes('wasser') || topicLower.includes('water') || topicLower.includes('nass') || topicLower.includes('wet')) {
if (topicLower.includes('sonnenlicht') && topicLower.includes('wasser') || topicLower.includes('sunlight') && topicLower.includes('water') ||
topicLower.includes('licht') && topicLower.includes('glas') || topicLower.includes('light') && topicLower.includes('glass') ||
topicLower.includes('prisma') || topicLower.includes('prism') || topicLower.includes('spektrum') || topicLower.includes('spectrum')) {
confusionFallback = isGerman ?
'Wenn Sonnenlicht durch ein Glas Wasser scheint, passiert etwas Magisches! Das weiße Licht wird in alle seine Farben aufgeteilt - rot, orange, gelb, grün, blau, indigo und violett. Das passiert, weil Licht eigentlich aus vielen Farben besteht, die wir normalerweise nicht sehen können. Das Wasser wirkt wie ein Prisma und trennt diese Farben. Du kannst es selbst ausprobieren: Halte ein Glas Wasser ins Sonnenlicht und schau an die Wand - du siehst einen kleinen Regenbogen! 🌈✨' :
'When sunlight shines through a glass of water, something magical happens! The white light gets split into all its colors - red, orange, yellow, green, blue, indigo, and violet. This happens because light is actually made of many colors that we normally can\'t see. The water acts like a prism and separates these colors. You can try it yourself: hold a glass of water in sunlight and look at the wall - you\'ll see a little rainbow! 🌈✨';
} else 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. 💧';
@@ -692,9 +698,20 @@ The child is asking for a definition, explanation, or clarification about locati
// Fallback for definition requests
const isGerman = language === 'de';
const definitionFallback = isGerman ?
'Das ist eine tolle Frage! Ein Regenbogen entsteht, wenn Sonnenlicht durch kleine Wassertropfen in der Luft geht. Das Licht wird dabei in alle seine Farben aufgeteilt - rot, orange, gelb, grün, blau, indigo und violett. Du kannst das auch mit einem Gartenschlauch ausprobieren! Was möchtest du noch wissen? 🌈' :
'That\'s a great question! A rainbow happens when sunlight goes through tiny water droplets in the air. The light gets split into all its colors - red, orange, yellow, green, blue, indigo, and violet. You can try this with a garden hose too! What else would you like to know? 🌈';
const { originalTopic } = req.body;
const topicLowerDef = (originalTopic || question || answer || '').toLowerCase();
let definitionFallback;
if (topicLowerDef.includes('sonnenlicht') && topicLowerDef.includes('wasser') || topicLowerDef.includes('sunlight') && topicLowerDef.includes('water') ||
topicLowerDef.includes('licht') && topicLowerDef.includes('glas') || topicLowerDef.includes('light') && topicLowerDef.includes('glass')) {
definitionFallback = isGerman ?
'Wenn Sonnenlicht durch ein Glas Wasser scheint, wird das weiße Licht in seine Farben aufgeteilt! Das nennt man Lichtbrechung oder Spektrum. Du siehst dann einen kleinen Regenbogen an der Wand. Das passiert, weil Licht aus vielen Farben besteht. Du kannst das ganz einfach selbst ausprobieren - halte ein Glas Wasser ins Sonnenlicht! Was möchtest du noch über Licht wissen? 🌈💡' :
'When sunlight shines through a glass of water, the white light gets split into its colors! This is called light refraction or spectrum. You\'ll see a little rainbow on the wall. This happens because light is made of many colors. You can easily try this yourself - hold a glass of water in sunlight! What else would you like to know about light? 🌈💡';
} else {
definitionFallback = isGerman ?
'Das ist eine tolle Frage! Ein Regenbogen entsteht, wenn Sonnenlicht durch kleine Wassertropfen in der Luft geht. Das Licht wird dabei in alle seine Farben aufgeteilt - rot, orange, gelb, grün, blau, indigo und violett. Du kannst das auch mit einem Gartenschlauch ausprobieren! Was möchtest du noch wissen? 🌈' :
'That\'s a great question! A rainbow happens when sunlight goes through tiny water droplets in the air. The light gets split into all its colors - red, orange, yellow, green, blue, indigo, and violet. You can try this with a garden hose too! What else would you like to know? 🌈';
}
return res.json({
success: true,

View File

@@ -3,17 +3,13 @@ nohup: ignoring input
🚀 KidsAI Explorer server running on port 3002
📖 Visit http://localhost:3002 to start exploring!
🤖 AI Services: OpenAI=true, HuggingFace=true
📝 Generating response to answer: "das weiß ich nicht" for question: "Warum ist Wasser nass?" with context: repeated_dont_know
🔍 Answer analysis - isDontKnow: true, answer: "das weiß ich nicht"
🎯 Detected repeated "don't know" - providing explanation instead of more questions
✅ OpenAI explanation for repeated "don't know" generated successfully
📝 Generating response to answer: "es ist feucht" for question: "Wie fühlt sich Wasser an?" with context: undefined
🔍 Answer analysis - isDontKnow: false, answer: "es ist feucht"
✅ OpenAI response generated successfully
📝 Generating response to answer: "das weiß ich nicht" for question: "Warum fühlt sich Wasser so an?" with context: undefined
🔍 Answer analysis - isDontKnow: true, answer: "das weiß ich nicht"
✅ OpenAI response generated successfully
📝 Generating response to answer: "das weiß ich nicht" for question: "Test" with context: repeated_dont_know
📝 Generating response to answer: "das weiß ich nicht" for question: "Was denkst du, könnte passieren, wenn das Licht durch das Wasser scheint, und wie könnte das aussehen?" with context: chat
🔍 Answer analysis - isDontKnow: true, answer: "das weiß ich nicht"
✅ OpenAI response generated successfully
📝 Generating response to answer: "das weiß ich nicht" for question: "Was denkst du, könnte passieren, wenn das Licht durch das Wasser scheint, und wie könnte das aussehen?" with context: chat
🔍 Answer analysis - isDontKnow: true, answer: "das weiß ich nicht"
✅ OpenAI response generated successfully
📝 Generating response to answer: "das weiß ich nicht" for question: "Was denkst du, könnte passieren, wenn das Licht durch das Wasser scheint, und wie könnte das aussehen?" with context: repeated_dont_know
🔍 Answer analysis - isDontKnow: true, answer: "das weiß ich nicht"
🎯 Detected repeated "don't know" - providing explanation instead of more questions
✅ OpenAI explanation for repeated "don't know" generated successfully