✨ 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);
|
}, 100);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="translations.js?v=20250629175000"></script>
|
<script src="translations.js?v=20250629180600"></script>
|
||||||
<script src="ai-responses.js?v=20250629175000"></script>
|
<script src="ai-responses.js?v=20250629180600"></script>
|
||||||
<script src="script-new.js?v=20250629175000"></script>
|
<script src="script-new.js?v=20250629180600"></script>
|
||||||
|
|
||||||
<!-- Inline debugging script -->
|
<!-- Inline debugging script -->
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -546,15 +546,29 @@ class KidsAIExplorer {
|
|||||||
|
|
||||||
askNextQuestion() {
|
askNextQuestion() {
|
||||||
if (this.currentQuestionIndex >= this.questions.length) {
|
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
|
// All questions asked, add and show reveal section
|
||||||
const revealDiv = document.createElement('div');
|
const revealDiv = document.createElement('div');
|
||||||
revealDiv.className = 'reveal-section';
|
revealDiv.className = 'reveal-section';
|
||||||
revealDiv.innerHTML = `
|
revealDiv.innerHTML = `
|
||||||
<div class="reveal-prompt">
|
<div class="reveal-prompt">
|
||||||
<p>🎉 Great thinking! You've explored this question step by step!</p>
|
<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}')">
|
<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>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="answer-content" id="answer-content" style="display: none;"></div>
|
<div class="answer-content" id="answer-content" style="display: none;"></div>
|
||||||
@@ -880,13 +894,28 @@ class KidsAIExplorer {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.success && data.answer) {
|
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
|
// Display the answer
|
||||||
answerContent.innerHTML = `
|
answerContent.innerHTML = `
|
||||||
<div class="final-answer">
|
<div class="final-answer">
|
||||||
<div class="answer-header">
|
<div class="answer-header">
|
||||||
<span class="answer-icon">💡</span>
|
<span class="answer-icon">${answerIcon}</span>
|
||||||
<h4>${this.currentLanguage === 'de' ? 'Die Antwort:' : 'The Answer:'}</h4>
|
<h4>${answerLabel}</h4>
|
||||||
<small class="answer-source">✨ AI • Scientific Explanation</small>
|
<small class="answer-source">${sourceLabel}</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="answer-text">
|
<div class="answer-text">
|
||||||
${data.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}"`);
|
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
|
// Create contextual prompt for responding to the user's answer
|
||||||
const isGerman = language === 'de';
|
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 ?
|
const contextualPrompt = isGerman ?
|
||||||
`Du bist ein pädagogischer KI-Assistent für Kinder. Ein Kind hat gerade auf eine Frage geantwortet.
|
`Du bist ein pädagogischer KI-Assistent für Kinder. Ein Kind hat gerade auf eine Frage geantwortet.
|
||||||
|
|
||||||
|
${subjectContext}
|
||||||
|
|
||||||
FRAGE: "${question}"
|
FRAGE: "${question}"
|
||||||
ANTWORT DES KINDES: "${answer}"
|
ANTWORT DES KINDES: "${answer}"
|
||||||
|
|
||||||
Deine Aufgabe ist es, eine ermutigende, pädagogische Antwort zu geben, die:
|
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)
|
1. Das Kind für seine Antwort ermutigt (egal ob richtig oder falsch)
|
||||||
2. Auf ihrer spezifischen Antwort aufbaut
|
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
|
4. Verwende Emojis sparsam und altersgerecht
|
||||||
|
|
||||||
WICHTIG: Stelle KEINE Folgefragen - antworte nur mit Ermutigung und Bestätigung in 1-2 Sätzen.` :
|
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.
|
`You are an educational AI assistant for children. A child just answered a question.
|
||||||
|
|
||||||
|
${subjectContext}
|
||||||
|
|
||||||
QUESTION: "${question}"
|
QUESTION: "${question}"
|
||||||
CHILD'S ANSWER: "${answer}"
|
CHILD'S ANSWER: "${answer}"
|
||||||
|
|
||||||
@@ -616,23 +642,51 @@ 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();
|
const answerLower = answer.toLowerCase();
|
||||||
let fallbackResponse;
|
let fallbackResponse;
|
||||||
|
|
||||||
if (answerLower.includes("don't know") || answerLower.includes("no idea") || answer.trim().length < 3) {
|
if (answerLower.includes("don't know") || answerLower.includes("no idea") || answer.trim().length < 3) {
|
||||||
|
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 ?
|
fallbackResponse = isGerman ?
|
||||||
"🌟 Das ist völlig in Ordnung! Nicht zu wissen bedeutet, dass wir zusammen etwas Neues entdecken können." :
|
"🌟 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.";
|
"🌟 That's completely okay! Not knowing means we get to discover something new together.";
|
||||||
} else if (answer.length < 15) {
|
}
|
||||||
|
} else if (answer === 'yes' || answer === 'yeah' || answer === 'yep') {
|
||||||
|
if (isMathQuestion) {
|
||||||
fallbackResponse = isGerman ?
|
fallbackResponse = isGerman ?
|
||||||
`💡 Interessante Überlegung zu "${answer}"! Du denkst in die richtige Richtung.` :
|
"👍 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) {
|
||||||
|
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.`;
|
`💡 Interesting thinking about "${answer}"! You're on the right track.`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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 {
|
} else {
|
||||||
fallbackResponse = isGerman ?
|
fallbackResponse = isGerman ?
|
||||||
`🎯 Ausgezeichnete Antwort! Du denkst wirklich gut über "${answer}" nach. Das zeigt, dass du das Konzept verstehst.` :
|
`🎯 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.`;
|
`🎯 Excellent answer! You're really thinking well about "${answer}". This shows you understand the concept.`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user