diff --git a/html/kidsai/server.js b/html/kidsai/server.js
index 094b85b..e7665c9 100755
--- a/html/kidsai/server.js
+++ b/html/kidsai/server.js
@@ -920,7 +920,8 @@ async function getConversationResponse(answer, question, originalTopic, language
'mit einem megafon', 'megafon', 'lautsprecher', 'trompete', 'glocke',
'rauchzeichen', 'signalfeuer', 'fahne schwenken', 'flagge', 'morse',
'brieftaube', 'taube', 'raven', 'eule', 'harry potter',
- 'magisch', 'zauberei', 'hexerei', 'telepathie', 'gedanken lesen'
+ 'magisch', 'zauberei', 'hexerei', 'telepathie', 'gedanken lesen',
+ 'farben', 'regenbogen', 'bunt', 'pink', 'lila', 'türkis'
] : [
'by fax', 'fax it', 'call them', 'phone call', 'write a letter',
'send mail', 'email them', 'whatsapp', 'telegram', 'instagram', 'tiktok',
@@ -928,12 +929,19 @@ async function getConversationResponse(answer, question, originalTopic, language
'megaphone', 'loudspeaker', 'trumpet', 'bell',
'smoke signals', 'signal fire', 'wave flag', 'flag', 'morse code',
'carrier pigeon', 'pigeon', 'raven', 'owl', 'harry potter',
- 'magic', 'wizardry', 'witchcraft', 'telepathy', 'mind reading'
+ 'magic', 'wizardry', 'witchcraft', 'telepathy', 'mind reading',
+ 'colors', 'rainbow', 'colorful', 'pink', 'purple', 'turquoise'
];
+ // Check for single-word creative answers (often all caps or unusual)
+ const isSingleWordCreative = answer.trim().length < 15 &&
+ (answer === answer.toUpperCase() ||
+ /^[A-ZÄÖÜ]+!*$/.test(answer.trim()) ||
+ ['farben', 'colors', 'regenbogen', 'rainbow', 'musik', 'music', 'tanzen', 'dancing'].includes(answer.toLowerCase().trim()));
+
const isHumorousAnswer = humorIndicators.some(indicator =>
answer.toLowerCase().includes(indicator)
- );
+ ) || isSingleWordCreative;
// Check for emotional/frustrated responses
const frustrationIndicators = isGerman ? [
@@ -942,14 +950,18 @@ async function getConversationResponse(answer, question, originalTopic, language
'will nicht', 'keine lust', 'ist schwer', 'ist zu schwer', 'ist kompliziert',
'macht keinen sinn', 'ist verwirrend', 'kapiere nicht', 'kapier nicht',
'ist unfair', 'ist gemein', 'warum muss ich', 'will aufhören',
- 'bin müde', 'bin genervt', 'ist anstrengend', 'zu viele fragen'
+ 'bin müde', 'bin genervt', 'ist anstrengend', 'zu viele fragen',
+ 'drehen uns im kreis', 'drehen sich im kreis', 'im kreis', 'freundchen',
+ 'langweilig', 'öde', 'öd', 'lahm', 'stupide'
] : [
'is stupid', 'is dumb', 'dont understand', "don't understand", 'dont get it', "don't get it",
'is boring', 'annoying', 'hate this', 'dont like', "don't like",
'dont want', "don't want", 'no point', 'is hard', 'too hard', 'complicated',
'makes no sense', 'confusing', 'dont get', "don't get",
'unfair', 'mean', 'why do i have to', 'want to stop',
- 'tired', 'annoyed', 'exhausting', 'too many questions'
+ 'tired', 'annoyed', 'exhausting', 'too many questions',
+ 'going in circles', 'round and round', 'circles', 'buddy', 'pal',
+ 'boring', 'tedious', 'lame', 'stupid'
];
const isEmotionalResponse = frustrationIndicators.some(indicator =>
diff --git a/html/kidsai/test-improved-responses.js b/html/kidsai/test-improved-responses.js
new file mode 100644
index 0000000..ccf2953
--- /dev/null
+++ b/html/kidsai/test-improved-responses.js
@@ -0,0 +1,173 @@
+#!/usr/bin/env node
+
+/**
+ * Test Script for Improved Response Handling
+ * Tests the specific issues from the conversation: frustration detection and creative answers
+ */
+
+const fetch = require('node-fetch');
+
+const BASE_URL = 'http://localhost:3002';
+
+const testCases = [
+ {
+ name: "Frustration with Repetition Test",
+ question: "Was denkst du, warum Menschen Programmiersprachen benutzen?",
+ answer: "Wir drehen uns im Kreis, Freundchen!",
+ originalTopic: "Programmiersprachen",
+ language: "de",
+ expectedBehavior: "Should recognize frustration and change approach"
+ },
+ {
+ name: "Creative Single Word Answer Test",
+ question: "Was denkst du, was eine Programmiersprache von einer normalen Sprache unterscheidet?",
+ answer: "FARBEN!",
+ originalTopic: "Programmiersprachen",
+ language: "de",
+ expectedBehavior: "Should acknowledge creativity, not say 'interessante Sichtweise'"
+ },
+ {
+ name: "Boredom Response Test",
+ question: "Warum haben Menschen Programmiersprachen erfunden?",
+ answer: "War ihnen vielleicht langweilig?",
+ originalTopic: "Programmiersprachen",
+ language: "de",
+ expectedBehavior: "Should handle potential boredom appropriately"
+ },
+ {
+ name: "Creative AI Answer Test",
+ question: "Was für eine App würdest du erstellen?",
+ answer: "Eine KI, die mich versteht",
+ originalTopic: "Programmierung",
+ language: "de",
+ expectedBehavior: "Should acknowledge the thoughtful answer positively"
+ }
+];
+
+async function testImprovedResponseHandling() {
+ console.log('🔧 Testing Improved Response Handling\n');
+ console.log('Based on real conversation issues...\n');
+
+ let passedTests = 0;
+ let totalTests = testCases.length;
+
+ for (const testCase of testCases) {
+ console.log('=' .repeat(60));
+ console.log(`TEST: ${testCase.name}`);
+ console.log('=' .repeat(60));
+ console.log(`Question: "${testCase.question}"`);
+ console.log(`Answer: "${testCase.answer}"`);
+ console.log(`Expected: ${testCase.expectedBehavior}`);
+ console.log();
+
+ try {
+ console.log('Sending request...');
+ const response = await fetch(`${BASE_URL}/api/respond-to-answer`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ answer: testCase.answer,
+ question: testCase.question,
+ originalTopic: testCase.originalTopic,
+ language: testCase.language,
+ sessionId: `test-improved-${Date.now()}`
+ })
+ });
+
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+
+ const data = await response.json();
+ const aiResponse = data.response || '';
+
+ console.log('\\n✅ Response received:');
+ console.log(`"${aiResponse}"`);
+
+ // Check if response is appropriate for each test case
+ const evaluation = evaluateResponse(aiResponse, testCase);
+
+ if (evaluation.isGood) {
+ console.log('✅ PASSED: ' + evaluation.reason);
+ passedTests++;
+ } else {
+ console.log('❌ FAILED: ' + evaluation.reason);
+ }
+
+ } catch (error) {
+ console.log('❌ FAILED: HTTP error!', error.message);
+ }
+
+ console.log();
+ }
+
+ console.log('=' .repeat(60));
+ console.log(`🎯 FINAL RESULTS: ${passedTests}/${totalTests} tests passed`);
+ console.log('=' .repeat(60));
+
+ const successRate = (passedTests / totalTests) * 100;
+ console.log(`📊 Success Rate: ${successRate.toFixed(1)}%`);
+
+ if (passedTests === totalTests) {
+ console.log('🎉 All tests passed! Improved response handling working correctly.');
+ } else {
+ console.log('⚠️ Some tests failed. Review response handling logic.');
+ }
+
+ return passedTests === totalTests;
+}
+
+function evaluateResponse(response, testCase) {
+ const responseLower = response.toLowerCase();
+
+ switch (testCase.name) {
+ case "Frustration with Repetition Test":
+ // Should NOT say "interessante Sichtweise" and SHOULD acknowledge frustration
+ if (responseLower.includes('interessante sichtweise') || responseLower.includes('interessante perspektive')) {
+ return { isGood: false, reason: 'Still using inappropriate "interessante Sichtweise" for frustration' };
+ }
+ if (responseLower.includes('verstehen') || responseLower.includes('frustrierend') || responseLower.includes('anders')) {
+ return { isGood: true, reason: 'Appropriately acknowledges frustration' };
+ }
+ return { isGood: false, reason: 'Does not appropriately handle frustration' };
+
+ case "Creative Single Word Answer Test":
+ // Should acknowledge creativity, not use generic response
+ if (responseLower.includes('interessante sichtweise') || responseLower.includes('interessante perspektive')) {
+ return { isGood: false, reason: 'Using generic "interessante Sichtweise" instead of acknowledging creativity' };
+ }
+ if (responseLower.includes('kreativ') || responseLower.includes('lustig') || responseLower.includes('farben') || responseLower.includes('bunt')) {
+ return { isGood: true, reason: 'Appropriately acknowledges creative answer about colors' };
+ }
+ return { isGood: false, reason: 'Does not appropriately acknowledge creativity' };
+
+ case "Boredom Response Test":
+ // Should handle boredom/disengagement appropriately
+ if (responseLower.includes('verstehen') || responseLower.includes('langweilig') || responseLower.includes('interessant')) {
+ return { isGood: true, reason: 'Appropriately handles potential boredom' };
+ }
+ return { isGood: false, reason: 'Does not handle boredom appropriately' };
+
+ case "Creative AI Answer Test":
+ // Should acknowledge the thoughtful answer positively
+ if (responseLower.includes('interessante sichtweise')) {
+ return { isGood: false, reason: 'Using generic response for thoughtful answer' };
+ }
+ if (responseLower.includes('toll') || responseLower.includes('gut') || responseLower.includes('verstehen')) {
+ return { isGood: true, reason: 'Appropriately acknowledges thoughtful answer' };
+ }
+ return { isGood: false, reason: 'Does not appropriately acknowledge thoughtful answer' };
+
+ default:
+ return { isGood: false, reason: 'Unknown test case' };
+ }
+}
+
+// Run the test
+if (require.main === module) {
+ setTimeout(() => {
+ testImprovedResponseHandling().catch(console.error);
+ }, 3000); // Wait for server to start
+}
+
+module.exports = { testImprovedResponseHandling };
diff --git a/html/kidsai/test-problematic-conversation.js b/html/kidsai/test-problematic-conversation.js
new file mode 100644
index 0000000..da5421a
--- /dev/null
+++ b/html/kidsai/test-problematic-conversation.js
@@ -0,0 +1,177 @@
+#!/usr/bin/env node
+
+/**
+ * Test Script for the Exact Problematic Conversation
+ * Simulates the conversation flow that showed issues with response handling
+ */
+
+const fetch = require('node-fetch');
+
+const BASE_URL = 'http://localhost:3002';
+
+async function testProblematicConversation() {
+ console.log('🔍 Testing the EXACT Problematic Conversation Flow\n');
+ console.log('Simulating the conversation that showed response issues...\n');
+
+ const sessionId = `problematic-conversation-${Date.now()}`;
+ let allPassed = true;
+
+ try {
+ // Step 1: Start conversation about programming languages
+ console.log('1️⃣ Starting conversation about programming languages...');
+ const step1 = await fetch(`${BASE_URL}/api/ask`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ question: "Warum haben Menschen Programmiersprachen erfunden?",
+ language: "de",
+ sessionId: sessionId
+ })
+ });
+
+ const step1Data = await step1.json();
+ console.log('🤖 AI Response:', step1Data.guidance?.steps?.[0]?.text || 'No response');
+
+ // Step 2: Child expresses potential boredom
+ console.log('\\n2️⃣ Child says "War ihnen vielleicht langweilig?"...');
+ const step2 = await fetch(`${BASE_URL}/api/respond-to-answer`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ answer: "War ihnen vielleicht langweilig?",
+ question: "Warum haben Menschen Programmiersprachen erfunden?",
+ originalTopic: "Programmiersprachen",
+ language: "de",
+ sessionId: sessionId
+ })
+ });
+
+ const step2Data = await step2.json();
+ const response2 = step2Data.response || '';
+ console.log('🤖 AI Response:', response2);
+
+ // Check if boredom is handled appropriately
+ if (response2.includes('verstehen') || response2.includes('okay')) {
+ console.log('✅ GOOD: Boredom handled appropriately');
+ } else {
+ console.log('❌ ISSUE: Boredom not handled well');
+ allPassed = false;
+ }
+
+ // Step 3: Child gives thoughtful answer about AI
+ console.log('\\n3️⃣ Child says "Eine KI, die mich versteht"...');
+ const step3 = await fetch(`${BASE_URL}/api/respond-to-answer`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ answer: "Eine KI, die mich versteht",
+ question: "Was für eine App würdest du erstellen?",
+ originalTopic: "Programmiersprachen",
+ language: "de",
+ sessionId: sessionId
+ })
+ });
+
+ const step3Data = await step3.json();
+ const response3 = step3Data.response || '';
+ console.log('🤖 AI Response:', response3);
+
+ // Check if thoughtful answer is acknowledged properly
+ if (response3.includes('interessante Sichtweise')) {
+ console.log('❌ ISSUE: Still using generic "interessante Sichtweise"');
+ allPassed = false;
+ } else if (response3.includes('toll') || response3.includes('gut') || response3.includes('idee')) {
+ console.log('✅ GOOD: Thoughtful answer acknowledged appropriately');
+ } else {
+ console.log('⚠️ NEUTRAL: Response could be more enthusiastic');
+ }
+
+ // Step 4: Child expresses frustration with repetition
+ console.log('\\n4️⃣ 🎯 CRITICAL TEST: Child says "Wir drehen uns im Kreis, Freundchen!"...');
+ const step4 = await fetch(`${BASE_URL}/api/respond-to-answer`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ answer: "Wir drehen uns im Kreis, Freundchen!",
+ question: "Was glaubst du, wie viele verschiedene Programmiersprachen es gibt?",
+ originalTopic: "Programmiersprachen",
+ language: "de",
+ sessionId: sessionId
+ })
+ });
+
+ const step4Data = await step4.json();
+ const response4 = step4Data.response || '';
+ console.log('🤖 AI Response:', response4);
+
+ // Check if frustration is handled appropriately
+ if (response4.includes('interessante Sichtweise') || response4.includes('interessante Perspektive')) {
+ console.log('❌ CRITICAL ISSUE: Still using inappropriate "interessante Sichtweise" for frustration');
+ allPassed = false;
+ } else if (response4.includes('verstehen') && (response4.includes('frustrierend') || response4.includes('kreis') || response4.includes('anders'))) {
+ console.log('✅ EXCELLENT: Frustration handled appropriately');
+ } else {
+ console.log('❌ ISSUE: Frustration not handled well');
+ allPassed = false;
+ }
+
+ // Step 5: Child gives creative single-word answer
+ console.log('\\n5️⃣ 🎯 CREATIVE TEST: Child says "FARBEN!"...');
+ const step5 = await fetch(`${BASE_URL}/api/respond-to-answer`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ answer: "FARBEN!",
+ question: "Was unterscheidet eine Programmiersprache von einer normalen Sprache?",
+ originalTopic: "Programmiersprachen",
+ language: "de",
+ sessionId: sessionId
+ })
+ });
+
+ const step5Data = await step5.json();
+ const response5 = step5Data.response || '';
+ console.log('🤖 AI Response:', response5);
+
+ // Check if creative answer is acknowledged properly
+ if (response5.includes('interessante Sichtweise') || response5.includes('interessante Perspektive')) {
+ console.log('❌ CRITICAL ISSUE: Still using generic "interessante Sichtweise" for creative answer');
+ allPassed = false;
+ } else if (response5.includes('lustig') || response5.includes('kreativ') || response5.includes('farben') || response5.includes('bunt')) {
+ console.log('✅ EXCELLENT: Creative answer acknowledged appropriately');
+ } else {
+ console.log('❌ ISSUE: Creative answer not acknowledged well');
+ allPassed = false;
+ }
+
+ console.log('\\n' + '='.repeat(70));
+ console.log('🎯 PROBLEMATIC CONVERSATION TEST RESULTS');
+ console.log('='.repeat(70));
+
+ if (allPassed) {
+ console.log('🎉 ALL ISSUES FIXED! The problematic conversation now works perfectly!');
+ console.log('✨ Key improvements verified:');
+ console.log(' • Boredom expressions handled with understanding');
+ console.log(' • Thoughtful answers acknowledged appropriately');
+ console.log(' • Frustration with repetition recognized and addressed');
+ console.log(' • Creative answers celebrated instead of dismissed');
+ console.log(' • No more inappropriate "interessante Sichtweise" responses');
+ console.log('\\n🚀 The conversation flow is now child-friendly and engaging!');
+ } else {
+ console.log('⚠️ Some issues remain. The AI needs further improvements.');
+ }
+
+ return allPassed;
+
+ } catch (error) {
+ console.error('❌ Test failed:', error.message);
+ return false;
+ }
+}
+
+// Run the test
+if (require.main === module) {
+ testProblematicConversation().catch(console.error);
+}
+
+module.exports = { testProblematicConversation };