From 597cd101e6263f4b9c350e775bb4ad10cbea4b30 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 29 Jun 2025 17:11:07 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20REFACTOR:=20Separate=20AI=20prompts?= =?UTF-8?q?=20into=20external=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created ai-responses.js to store all AI response prompts - Refactored generateContextualResponse() to use external AIResponses object - Added ai-responses.js script to index.html - Enhanced brake-specific responses for bicycle and car questions - Improved maintainability and prevents script corruption during edits - All contextual responses now centralized in structured object --- html/kidsai/ai-responses.js | 91 +++++++++++++++++++++++++++++++ html/kidsai/index.html | 58 ++++++++++++++++---- html/kidsai/script-new.js | 105 ++++++++++++++++++++++++++---------- 3 files changed, 216 insertions(+), 38 deletions(-) create mode 100644 html/kidsai/ai-responses.js diff --git a/html/kidsai/ai-responses.js b/html/kidsai/ai-responses.js new file mode 100644 index 0000000..3445f3b --- /dev/null +++ b/html/kidsai/ai-responses.js @@ -0,0 +1,91 @@ +// AI Response Configuration +// This file contains all the contextual responses for the KidsAI system +// Separated from main script to prevent corruption during edits + +const AIResponses = { + // Handle "I don't know" or help-seeking responses + helpSeeking: { + dontKnow: "That's perfectly fine! ๐Ÿค— Not knowing something just means we're about to learn something new together. Let's keep exploring!", + whatIsIt: "That's a great question! ๐Ÿ˜Š That's exactly what we're exploring together - let's discover it step by step!", + tellMe: "I love your curiosity! ๐ŸŒŸ Instead of telling you directly, let's think through it together so you can discover it yourself!" + }, + + // Short answer responses + shortAnswers: { + yes: { + bicycle: "Great! ๐Ÿšดโ€โ™‚๏ธ Since you have bicycle experience, you understand how mechanical controls work. That's perfect for what we're exploring!", + general: "Perfect! ๐ŸŒŸ I can see you're following along. Let's dive a bit deeper!", + knowledge: "Excellent! ๐Ÿ‘ Your knowledge will help us build on these concepts together!" + }, + no: "No problem at all! ๐Ÿ˜Š That's why we're exploring this together - to discover new things!" + }, + + // Topic-specific responses + bicycle: { + brake: { + slowDown: "๐Ÿšดโ€โ™‚๏ธ Exactly right! You understand that brakes slow you down and stop you. That's the basic function we need to understand!", + technical: "๐ŸŽฏ Great technical thinking! You understand how the brake mechanism works on the wheel!", + general: "๐Ÿค” Tell me more about what happens when you use bicycle brakes." + }, + mechanics: { + pedalChainWheel: "๐Ÿšดโ€โ™‚๏ธ Excellent! You understand the connection between pedals, chain, and wheels. That mechanical connection concept is key!", + gearSpeed: "โš™๏ธ Yes! You're thinking about how we control speed and power - that's exactly right!", + slowStop: "๐Ÿšดโ€โ™‚๏ธ Right! You understand the basic control functions of bicycles!" + } + }, + + car: { + brake: { + perfectAnswer: "๐ŸŽฏ EXACTLY! ๐Ÿš— Yes, it's the brake system! Perfect answer - the brake pedal controls the brakes that slow down or stop the car!", + brakeAndPedal: "๐Ÿ† Perfect! The brake pedal and brake system work together to control the car's speed. You nailed it!", + justBrake: "๐ŸŽฏ YES! The brakes! You got it exactly right! The brake system is what slows down and stops the car!", + wheelTire: "๐Ÿ‘ You're thinking about where the braking happens - at the wheels! The brake system applies pressure there.", + pedal: "๐Ÿฆถ Good! You're thinking about pedals. Which specific pedal controls stopping?", + general: "๐Ÿค” What component do you think actually does the slowing down in a car?" + }, + comparison: { + engine: "๐Ÿš— You're thinking about the engine - that's the power source! But I'm thinking of a specific part that works between the engine and wheels, kind of like how bike pedals connect to the chain.", + gearTransmission: "๐ŸŽฏ Great thinking! You're absolutely on the right track with gears and transmission systems!", + pedalBrake: "๐Ÿฆถ Good connection! You're thinking about pedals in cars. There are actually multiple pedals that do different things!" + }, + clutch: { + perfect: "๐ŸŽฏ Perfect! You know about the clutch! That's exactly what I was thinking of - the component that helps with smooth gear changes!", + transmission: "๐Ÿ”ง Excellent! You're thinking about the transmission system. The clutch is the part that connects and disconnects the engine from the gearbox!", + separate: "๐Ÿ‘ Yes! You understand the separation concept - that's exactly what the clutch does!", + different: "๐Ÿ’ก Good observation! You're noticing that clutch and brake do different things. That's key insight!", + engineTransmission: "๐Ÿš— Excellent! You're thinking about the engine and transmission connection - that's exactly what the clutch controls!", + general: "๐Ÿค” The clutch is quite different from the brake. What do you think it might do instead of slowing down?" + }, + trafficLight: { + clutchNeutral: "๐Ÿšฆ Perfect! You understand that something allows the engine to keep running while the car is stopped!", + disconnect: "๐Ÿ’ก Exactly! Something disconnects the wheels from the engine so it can keep running while stopped!", + brakePark: "๐Ÿ›‘ You're thinking about stopping the car, which is important! But I'm thinking of how the engine can keep running while the wheels aren't moving." + } + }, + + // Bird flight responses + birds: { + pushAirLift: "๐Ÿฆ Fantastic! You understand that it's all about air and creating lift! That's exactly how flight works!", + featherAirflow: "โœจ Brilliant! Feathers and airflow are absolutely key to how birds fly!", + flapMove: "๐ŸŒŸ Perfect! Wing movement creates the forces that allow birds to fly!" + }, + + // General mechanical understanding + mechanical: { + connectControl: "๐Ÿ”ง Excellent mechanical thinking! You understand that cars have systems that connect and control different parts!" + }, + + // Generic responses based on answer quality (last resort) + generic: { + veryDetailed: "๐ŸŒŸ I appreciate your detailed explanation! You're really working through this systematically.", + detailed: "๐Ÿ‘ Good thinking! I can see you're considering different aspects of this.", + medium: "๐Ÿ’ญ Interesting! Can you help me understand your reasoning a bit more?", + short: "๐Ÿค” I see what you're thinking. Can you elaborate on that?", + veryShort: "๐Ÿ’ก Feel free to share any thoughts - every idea helps us learn!" + } +}; + +// Export for use in main script +if (typeof module !== 'undefined' && module.exports) { + module.exports = AIResponses; +} diff --git a/html/kidsai/index.html b/html/kidsai/index.html index 071bcf9..efdc084 100755 --- a/html/kidsai/index.html +++ b/html/kidsai/index.html @@ -1,8 +1,5 @@ - - - - ang="en"> + @@ -22,7 +19,7 @@ - + @@ -90,6 +87,20 @@

๐Ÿ’ก Let's Think Step by Step!

+ @@ -165,10 +176,39 @@ }, 100); - - + + + - - + + diff --git a/html/kidsai/script-new.js b/html/kidsai/script-new.js index 4c4e36c..c667486 100644 --- a/html/kidsai/script-new.js +++ b/html/kidsai/script-new.js @@ -603,86 +603,133 @@ class KidsAIExplorer { const currentQuestion = this.questions[questionIndex]; const questionLower = currentQuestion ? currentQuestion.toLowerCase() : ''; + // Ensure AIResponses is available + if (typeof AIResponses === 'undefined') { + console.warn('โš ๏ธ AIResponses not loaded, using fallback'); + return "๐ŸŒŸ Great thinking! Keep exploring - you're doing wonderfully!"; + } + // Handle "I don't know" or help-seeking responses - if (answerLower.includes('don\'t know') || answerLower.includes('no idea') || - answerLower.includes('what is it') || answerLower.includes('tell me') || - (answerLower === 'no' && questionLower.includes('heard of'))) { - return "That's perfectly fine! ๐Ÿค— Not knowing something just means we're about to learn something new together. Let's keep exploring!"; + if (answerLower.includes('don\'t know') || answerLower.includes('no idea')) { + return AIResponses.helpSeeking.dontKnow; + } + if (answerLower.includes('what is it')) { + return AIResponses.helpSeeking.whatIsIt; + } + if (answerLower.includes('tell me')) { + return AIResponses.helpSeeking.tellMe; } // Handle very short positive answers like "yes" if (answerLower === 'yes' || answerLower === 'yeah' || answerLower === 'yep') { if (questionLower.includes('bicycle') || questionLower.includes('pedal')) { - return "Great! ๐Ÿšดโ€โ™‚๏ธ Since you understand how bicycles work, you're already thinking about mechanical connections. That's exactly the kind of thinking we need!"; + return AIResponses.shortAnswers.yes.bicycle; } else if (questionLower.includes('heard of') || questionLower.includes('know')) { - return "Excellent! ๐Ÿ‘ Your knowledge will help us build on these concepts together!"; + return AIResponses.shortAnswers.yes.knowledge; } else { - return "Perfect! ๐ŸŒŸ I can see you're following along. Let's dive a bit deeper!"; + return AIResponses.shortAnswers.yes.general; } } // Handle "no" responses if (answerLower === 'no' || answerLower === 'nope') { - return "No problem at all! ๐Ÿ˜Š That's why we're exploring this together - to discover new things!"; + return AIResponses.shortAnswers.no; } - // Topic-specific contextual responses + // Topic-specific contextual responses - BICYCLE if (questionLower.includes('bicycle') || questionLower.includes('pedal') || questionLower.includes('chain')) { - if (answerLower.includes('pedal') || answerLower.includes('chain') || answerLower.includes('wheel')) { - return "๏ฟฝโ€โ™‚๏ธ Excellent! You understand the connection between pedals, chain, and wheels. That mechanical connection concept is key!"; + if (answerLower.includes('brake') && (answerLower.includes('slow') || answerLower.includes('stop'))) { + return AIResponses.bicycle.brake.slowDown; + } else if (answerLower.includes('brake')) { + return AIResponses.bicycle.brake.technical; + } else if (answerLower.includes('pedal') || answerLower.includes('chain') || answerLower.includes('wheel')) { + return AIResponses.bicycle.mechanics.pedalChainWheel; } else if (answerLower.includes('gear') || answerLower.includes('speed')) { - return "๐Ÿ‘ Yes! You're thinking about how we control speed and power - that's exactly right!"; + return AIResponses.bicycle.mechanics.gearSpeed; + } else if (answerLower.includes('slow') || answerLower.includes('stop')) { + return AIResponses.bicycle.mechanics.slowStop; } } + // CAR vs BICYCLE comparison if (questionLower.includes('car') && questionLower.includes('bicycle')) { if (answerLower.includes('engine')) { - return "๏ฟฝ You're thinking about the engine - that's the power source! But I'm thinking of a specific part that works between the engine and wheels, kind of like how bike pedals connect to the chain."; + return AIResponses.car.comparison.engine; } else if (answerLower.includes('gear') || answerLower.includes('transmission')) { - return "๐ŸŽฏ Great thinking! You're absolutely on the right track with gears and transmission systems!"; + return AIResponses.car.comparison.gearTransmission; } else if (answerLower.includes('pedal') || answerLower.includes('brake')) { - return "๐Ÿฆถ Good connection! You're thinking about pedals in cars. There are actually multiple pedals that do different things!"; + return AIResponses.car.comparison.pedalBrake; } } + // CAR BRAKE responses + if (questionLower.includes('slow') || questionLower.includes('stop') || questionLower.includes('car')) { + if (answerLower.includes('brake') && (answerLower.includes('pedal') || answerLower.includes('system'))) { + return AIResponses.car.brake.perfectAnswer; + } else if (answerLower.includes('brake') && !answerLower.includes('clutch')) { + return AIResponses.car.brake.justBrake; + } else if (answerLower.includes('wheel') || answerLower.includes('tire')) { + return AIResponses.car.brake.wheelTire; + } else if (answerLower.includes('pedal') && !answerLower.includes('brake')) { + return AIResponses.car.brake.pedal; + } + } + + // CLUTCH responses if (questionLower.includes('clutch') || questionLower.includes('gears') || questionLower.includes('switch gears')) { if (answerLower.includes('clutch')) { - return "๐ŸŽฏ Perfect! You know about the clutch! That's exactly what I was thinking of - the component that helps with smooth gear changes!"; + return AIResponses.car.clutch.perfect; } else if (answerLower.includes('transmission') || answerLower.includes('gearbox')) { - return "๐Ÿ”ง Excellent! You're thinking about the transmission system. The clutch is the part that connects and disconnects the engine from the gearbox!"; + return AIResponses.car.clutch.transmission; } else if (answerLower.includes('separate') || answerLower.includes('disconnect')) { - return "๐Ÿ‘ Yes! You understand the separation concept - that's exactly what the clutch does!"; + return AIResponses.car.clutch.separate; + } else if (answerLower.includes('different') && answerLower.includes('brake')) { + return AIResponses.car.clutch.different; + } else if (answerLower.includes('engine') && answerLower.includes('transmission')) { + return AIResponses.car.clutch.engineTransmission; + } else { + return AIResponses.car.clutch.general; } } + // TRAFFIC LIGHT / ENGINE RUNNING responses if (questionLower.includes('traffic light') || questionLower.includes('stopped') || questionLower.includes('engine running')) { if (answerLower.includes('clutch') || answerLower.includes('neutral')) { - return "๐Ÿšฆ Brilliant! You understand that we need a way to keep the engine running while the car is stopped!"; + return AIResponses.car.trafficLight.clutchNeutral; + } else if (answerLower.includes('disconnect') || answerLower.includes('separate')) { + return AIResponses.car.trafficLight.disconnect; } else if (answerLower.includes('brake') || answerLower.includes('park')) { - return "๐Ÿ›‘ You're thinking about stopping the car, which is important! But I'm thinking of how the engine can keep running while the wheels aren't moving."; + return AIResponses.car.trafficLight.brakePark; } } - // Bird flight responses + // BIRD FLIGHT responses if (questionLower.includes('bird') || questionLower.includes('wing') || questionLower.includes('fly')) { if (answerLower.includes('push') || answerLower.includes('air') || answerLower.includes('lift')) { - return "๏ฟฝ Fantastic! You understand that it's all about air and creating lift! That's exactly how flight works!"; + return AIResponses.birds.pushAirLift; } else if (answerLower.includes('feather') || answerLower.includes('airflow')) { - return "โœจ Brilliant! Feathers and airflow are absolutely key to how birds fly!"; + return AIResponses.birds.featherAirflow; } else if (answerLower.includes('flap') || answerLower.includes('move')) { - return "๐ŸŒŸ Perfect! Wing movement creates the forces that allow birds to fly!"; + return AIResponses.birds.flapMove; } } + // MECHANICAL understanding responses + if (answerLower.includes('connect') || answerLower.includes('control')) { + return AIResponses.mechanical.connectControl; + } + // Generic responses based on answer quality and engagement if (answer.length > 25) { - return "๐ŸŒŸ I love your detailed thinking! You're really exploring this concept thoroughly. That kind of curiosity is what leads to great discoveries!"; - } else if (answer.length > 10) { - return "๐Ÿ‘ Good observation! I can see you're thinking about this carefully. Your reasoning is developing nicely!"; + return AIResponses.generic.veryDetailed; + } else if (answer.length > 15) { + return AIResponses.generic.detailed; + } else if (answer.length > 8) { + return AIResponses.generic.medium; } else if (answer.length > 3) { - return "๏ฟฝ Interesting thought! You're engaging with the concept. Can you help me understand your thinking a bit more?"; + return AIResponses.generic.short; } else { - return "๐Ÿค” I see you're thinking about this! Feel free to share whatever comes to mind - there are no wrong answers here!"; + return AIResponses.generic.veryShort; } }