✨ ENHANCE: Subject-aware AI responses for Math vs Science
IMPROVEMENTS: 🔢 Math Questions: - Detects math questions (contains +, -, numbers, sum, total, count) - AI responses focus on mathematical thinking and counting - 'yes' → 'Great! Math is fun when we take it step by step.' - Answer reveals show '🔢 Mathematical Solution' not 'Scientific Explanation' - Button text: 'Show Solution!' instead of 'Reveal Answer!' 🔬 Science Questions: - Maintains scientific focus for how/why questions - AI responses focus on scientific discovery and exploration - Proper 'Scientific Explanation' labeling for science topics 🎯 Better Fallback Responses: - Math-specific encouragement for numbers and counting - Subject-appropriate emojis and language - More relevant feedback for different question types BEFORE: '10+5' → 'Scientific Explanation' ❌ NOW: '10+5' → '🔢 Mathematical Solution' ✅
This commit is contained in:
@@ -176,9 +176,9 @@
|
||||
}, 100);
|
||||
</script>
|
||||
|
||||
<script src="translations.js?v=20250629175000"></script>
|
||||
<script src="ai-responses.js?v=20250629175000"></script>
|
||||
<script src="script-new.js?v=20250629175000"></script>
|
||||
<script src="translations.js?v=20250629180600"></script>
|
||||
<script src="ai-responses.js?v=20250629180600"></script>
|
||||
<script src="script-new.js?v=20250629180600"></script>
|
||||
|
||||
<!-- Inline debugging script -->
|
||||
<script>
|
||||
|
||||
@@ -546,15 +546,29 @@ class KidsAIExplorer {
|
||||
|
||||
askNextQuestion() {
|
||||
if (this.currentQuestionIndex >= this.questions.length) {
|
||||
// Detect question type for appropriate reveal text
|
||||
const originalQuestion = this.questionInput.value.toLowerCase();
|
||||
const isMathQuestion = originalQuestion.includes('+') || originalQuestion.includes('-') ||
|
||||
originalQuestion.includes('×') || originalQuestion.includes('÷') ||
|
||||
originalQuestion.includes('sum') || originalQuestion.includes('total') ||
|
||||
/\d+.*\d+/.test(originalQuestion);
|
||||
|
||||
const revealText = isMathQuestion
|
||||
? "Would you like to see the mathematical solution?"
|
||||
: "Would you like to see how close your thoughts were to the scientific explanation?";
|
||||
|
||||
const revealIcon = isMathQuestion ? "🔢" : "🎯";
|
||||
const buttonText = isMathQuestion ? "Show Solution!" : "Reveal Answer!";
|
||||
|
||||
// All questions asked, add and show reveal section
|
||||
const revealDiv = document.createElement('div');
|
||||
revealDiv.className = 'reveal-section';
|
||||
revealDiv.innerHTML = `
|
||||
<div class="reveal-prompt">
|
||||
<p>🎉 Great thinking! You've explored this question step by step!</p>
|
||||
<p>Would you like to see how close your thoughts were to the scientific explanation?</p>
|
||||
<p>${revealText}</p>
|
||||
<button class="reveal-btn" onclick="kidsAI.revealAnswer('${this.questionInput.value}')">
|
||||
<span class="btn-icon">🎯</span> Reveal Answer!
|
||||
<span class="btn-icon">${revealIcon}</span> ${buttonText}
|
||||
</button>
|
||||
</div>
|
||||
<div class="answer-content" id="answer-content" style="display: none;"></div>
|
||||
@@ -880,13 +894,28 @@ class KidsAIExplorer {
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success && data.answer) {
|
||||
// Detect question type for appropriate labeling
|
||||
const originalQuestion = question.toLowerCase();
|
||||
const isMathQuestion = originalQuestion.includes('+') || originalQuestion.includes('-') ||
|
||||
originalQuestion.includes('×') || originalQuestion.includes('÷') ||
|
||||
originalQuestion.includes('sum') || originalQuestion.includes('total') ||
|
||||
/\d+.*\d+/.test(originalQuestion);
|
||||
|
||||
const answerIcon = isMathQuestion ? "🔢" : "💡";
|
||||
const answerLabel = isMathQuestion
|
||||
? (this.currentLanguage === 'de' ? 'Die Lösung:' : 'The Solution:')
|
||||
: (this.currentLanguage === 'de' ? 'Die Antwort:' : 'The Answer:');
|
||||
const sourceLabel = isMathQuestion
|
||||
? "🔢 AI • Mathematical Solution"
|
||||
: "✨ AI • Scientific Explanation";
|
||||
|
||||
// Display the answer
|
||||
answerContent.innerHTML = `
|
||||
<div class="final-answer">
|
||||
<div class="answer-header">
|
||||
<span class="answer-icon">💡</span>
|
||||
<h4>${this.currentLanguage === 'de' ? 'Die Antwort:' : 'The Answer:'}</h4>
|
||||
<small class="answer-source">✨ AI • Scientific Explanation</small>
|
||||
<span class="answer-icon">${answerIcon}</span>
|
||||
<h4>${answerLabel}</h4>
|
||||
<small class="answer-source">${sourceLabel}</small>
|
||||
</div>
|
||||
<div class="answer-text">
|
||||
${data.answer.text}
|
||||
|
||||
@@ -557,24 +557,50 @@ app.post('/api/respond-to-answer', async (req, res) => {
|
||||
|
||||
console.log(`📝 Generating response to answer: "${answer}" for question: "${question}"`);
|
||||
|
||||
// Detect question type for better responses
|
||||
const questionLower = question.toLowerCase();
|
||||
const isMathQuestion = questionLower.includes('+') || questionLower.includes('-') ||
|
||||
questionLower.includes('×') || questionLower.includes('÷') ||
|
||||
questionLower.includes('sum') || questionLower.includes('total') ||
|
||||
questionLower.includes('count') || /\d+.*\d+/.test(questionLower);
|
||||
|
||||
const isScienceQuestion = questionLower.includes('how') || questionLower.includes('why') ||
|
||||
questionLower.includes('what makes') || questionLower.includes('engine') ||
|
||||
questionLower.includes('work') || questionLower.includes('breath');
|
||||
|
||||
// Create contextual prompt for responding to the user's answer
|
||||
const isGerman = language === 'de';
|
||||
|
||||
let subjectContext = '';
|
||||
if (isMathQuestion) {
|
||||
subjectContext = isGerman ?
|
||||
'Dies ist eine Mathematikfrage. Konzentriere dich auf Zahlen, Zählen und mathematisches Denken.' :
|
||||
'This is a math question. Focus on numbers, counting, and mathematical thinking.';
|
||||
} else if (isScienceQuestion) {
|
||||
subjectContext = isGerman ?
|
||||
'Dies ist eine Wissenschaftsfrage. Konzentriere dich auf wissenschaftliches Denken und Entdeckung.' :
|
||||
'This is a science question. Focus on scientific thinking and discovery.';
|
||||
}
|
||||
|
||||
const contextualPrompt = isGerman ?
|
||||
`Du bist ein pädagogischer KI-Assistent für Kinder. Ein Kind hat gerade auf eine Frage geantwortet.
|
||||
|
||||
${subjectContext}
|
||||
|
||||
FRAGE: "${question}"
|
||||
ANTWORT DES KINDES: "${answer}"
|
||||
|
||||
Deine Aufgabe ist es, eine ermutigende, pädagogische Antwort zu geben, die:
|
||||
1. Das Kind für seine Antwort ermutigt (egal ob richtig oder falsch)
|
||||
2. Auf ihrer spezifischen Antwort aufbaut
|
||||
3. Ihr Denken würdigt und erweitert
|
||||
3. Ihr Denken würdigt und erweitert, passend zum Fachbereich
|
||||
4. Verwende Emojis sparsam und altersgerecht
|
||||
|
||||
WICHTIG: Stelle KEINE Folgefragen - antworte nur mit Ermutigung und Bestätigung in 1-2 Sätzen.` :
|
||||
`You are an educational AI assistant for children. A child just answered a question.
|
||||
|
||||
${subjectContext}
|
||||
|
||||
QUESTION: "${question}"
|
||||
CHILD'S ANSWER: "${answer}"
|
||||
|
||||
@@ -616,22 +642,50 @@ IMPORTANT: Do NOT ask follow-up questions - only respond with encouragement and
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Generate a contextual response based on answer content
|
||||
// Fallback: Generate a contextual response based on answer content and subject
|
||||
const answerLower = answer.toLowerCase();
|
||||
let fallbackResponse;
|
||||
|
||||
if (answerLower.includes("don't know") || answerLower.includes("no idea") || answer.trim().length < 3) {
|
||||
fallbackResponse = isGerman ?
|
||||
"🌟 Das ist völlig in Ordnung! Nicht zu wissen bedeutet, dass wir zusammen etwas Neues entdecken können." :
|
||||
"🌟 That's completely okay! Not knowing means we get to discover something new together.";
|
||||
if (isMathQuestion) {
|
||||
fallbackResponse = isGerman ?
|
||||
"🌟 Das ist völlig in Ordnung! Mathematik kann knifflig sein. Lass uns zusammen zählen und herausfinden!" :
|
||||
"🌟 That's completely okay! Math can be tricky. Let's count together and figure it out!";
|
||||
} else {
|
||||
fallbackResponse = isGerman ?
|
||||
"🌟 Das ist völlig in Ordnung! Nicht zu wissen bedeutet, dass wir zusammen etwas Neues entdecken können." :
|
||||
"🌟 That's completely okay! Not knowing means we get to discover something new together.";
|
||||
}
|
||||
} else if (answer === 'yes' || answer === 'yeah' || answer === 'yep') {
|
||||
if (isMathQuestion) {
|
||||
fallbackResponse = isGerman ?
|
||||
"👍 Großartig! Mathematik macht Spaß, wenn wir Schritt für Schritt vorgehen." :
|
||||
"👍 Great! Math is fun when we take it step by step.";
|
||||
} else {
|
||||
fallbackResponse = isGerman ?
|
||||
"👍 Wunderbar! Du bist bereit zu lernen und zu entdecken." :
|
||||
"👍 Wonderful! You're ready to learn and explore.";
|
||||
}
|
||||
} else if (answer.length < 15) {
|
||||
fallbackResponse = isGerman ?
|
||||
`💡 Interessante Überlegung zu "${answer}"! Du denkst in die richtige Richtung.` :
|
||||
`💡 Interesting thinking about "${answer}"! You're on the right track.`;
|
||||
if (isMathQuestion) {
|
||||
fallbackResponse = isGerman ?
|
||||
`<EFBFBD> Gute Arbeit mit "${answer}"! Du denkst mathematisch.` :
|
||||
`🔢 Good work with "${answer}"! You're thinking mathematically.`;
|
||||
} else {
|
||||
fallbackResponse = isGerman ?
|
||||
`<EFBFBD>💡 Interessante Überlegung zu "${answer}"! Du denkst in die richtige Richtung.` :
|
||||
`💡 Interesting thinking about "${answer}"! You're on the right track.`;
|
||||
}
|
||||
} else {
|
||||
fallbackResponse = isGerman ?
|
||||
`🎯 Ausgezeichnete Antwort! Du denkst wirklich gut über "${answer}" nach. Das zeigt, dass du das Konzept verstehst.` :
|
||||
`🎯 Excellent answer! You're really thinking well about "${answer}". This shows you understand the concept.`;
|
||||
if (isMathQuestion) {
|
||||
fallbackResponse = isGerman ?
|
||||
`🎯 Ausgezeichnet! Du hast "${answer}" richtig herausgefunden. Deine mathematischen Fähigkeiten werden immer besser!` :
|
||||
`🎯 Excellent! You figured out "${answer}" correctly. Your math skills are getting stronger!`;
|
||||
} else {
|
||||
fallbackResponse = isGerman ?
|
||||
`🎯 Ausgezeichnete Antwort! Du denkst wirklich gut über "${answer}" nach. Das zeigt, dass du das Konzept verstehst.` :
|
||||
`🎯 Excellent answer! You're really thinking well about "${answer}". This shows you understand the concept.`;
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
|
||||
Reference in New Issue
Block a user