🔧 Fix Socratic teaching logic
- Fixed the critical issue where AI was giving direct answers instead of asking guiding questions - Now when child answers 'no' or 'don't know', system calls /api/ask for Socratic guidance - When child gives substantial answers, system calls /api/respond-to-answer for validation - Applied fix to both chat mode and step-by-step mode - Enhanced answer analysis to detect negative/unknown responses vs substantial answers - Updated response handling to work with both guidance format and simple response format This ensures the AI acts as a true Socratic teacher, guiding discovery rather than giving answers.
This commit is contained in:
@@ -415,10 +415,36 @@ class KidsAIExplorer {
|
|||||||
? this.currentSteps[stepIndex].text
|
? this.currentSteps[stepIndex].text
|
||||||
: 'the current question';
|
: 'the current question';
|
||||||
|
|
||||||
console.log('📤 Sending request to /api/respond-to-answer:', { answer, currentQuestion });
|
// Analyze the answer to determine the appropriate response type
|
||||||
|
const answerLower = answer.toLowerCase().trim();
|
||||||
|
const isNegative = answerLower === 'no' || answerLower === 'nein' || answerLower === 'nope' || answerLower === 'nei';
|
||||||
|
const isDontKnow = answerLower.includes("don't know") || answerLower.includes('weiß nicht') || answerLower.includes('keine ahnung') || answer.trim().length < 3;
|
||||||
|
|
||||||
// Call server API for contextual response
|
let response;
|
||||||
const response = await fetch('/api/respond-to-answer', {
|
|
||||||
|
if (isNegative || isDontKnow) {
|
||||||
|
// For "no" or "don't know" answers, get Socratic guidance questions
|
||||||
|
console.log('📤 Sending guidance request to /api/ask for Socratic questioning');
|
||||||
|
|
||||||
|
const guidancePrompt = this.currentLanguage === 'de'
|
||||||
|
? `Ein Kind hat "${answer}" geantwortet auf die Frage "${currentQuestion}". Führe es durch Socratic Fragen zur Entdeckung, ohne direkte Antworten zu geben.`
|
||||||
|
: `A child answered "${answer}" to the question "${currentQuestion}". Guide them through Socratic questions to discovery without giving direct answers.`;
|
||||||
|
|
||||||
|
response = await fetch('/api/ask', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
question: guidancePrompt,
|
||||||
|
language: this.currentLanguage
|
||||||
|
})
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// For substantial answers, acknowledge and validate
|
||||||
|
console.log('📤 Sending validation request to /api/respond-to-answer');
|
||||||
|
|
||||||
|
response = await fetch('/api/respond-to-answer', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -430,6 +456,7 @@ class KidsAIExplorer {
|
|||||||
stepIndex: stepIndex
|
stepIndex: stepIndex
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log('📥 Server response status:', response.status);
|
console.log('📥 Server response status:', response.status);
|
||||||
|
|
||||||
@@ -440,7 +467,25 @@ class KidsAIExplorer {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('✅ Server response data:', data);
|
console.log('✅ Server response data:', data);
|
||||||
|
|
||||||
if (data.success && data.response) {
|
let responseContent = '';
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
if (data.guidance && data.guidance.steps) {
|
||||||
|
// Response from /api/ask with Socratic guidance steps
|
||||||
|
const steps = data.guidance.steps.slice(0, 3); // Limit to 3 steps
|
||||||
|
responseContent = steps.map((step, index) =>
|
||||||
|
`<p><strong>${index + 1}.</strong> ${step.text}</p>`
|
||||||
|
).join('');
|
||||||
|
} else if (data.response) {
|
||||||
|
// Simple response from /api/respond-to-answer
|
||||||
|
responseContent = `<p>${data.response}</p>`;
|
||||||
|
} else {
|
||||||
|
// Fallback
|
||||||
|
responseContent = this.currentLanguage === 'de'
|
||||||
|
? '<p>🤔 Das ist eine interessante Frage! Lass uns zusammen darüber nachdenken...</p>'
|
||||||
|
: '<p>🤔 That\'s an interesting question! Let\'s think about it together...</p>';
|
||||||
|
}
|
||||||
|
|
||||||
responseDiv.innerHTML = `
|
responseDiv.innerHTML = `
|
||||||
<div class="ai-response-content">
|
<div class="ai-response-content">
|
||||||
<div class="message-header">
|
<div class="message-header">
|
||||||
@@ -448,7 +493,7 @@ class KidsAIExplorer {
|
|||||||
<span class="ai-label">${this.getTranslation('ai-teacher')}</span>
|
<span class="ai-label">${this.getTranslation('ai-teacher')}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="message-content">
|
<div class="message-content">
|
||||||
<p>${data.response}</p>
|
${responseContent}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -509,10 +554,36 @@ class KidsAIExplorer {
|
|||||||
// Get the original topic for better context
|
// Get the original topic for better context
|
||||||
const originalQuestion = this.questionInput ? this.questionInput.value.trim() : '';
|
const originalQuestion = this.questionInput ? this.questionInput.value.trim() : '';
|
||||||
|
|
||||||
console.log('📤 Sending chat request to /api/respond-to-answer:', { answer, currentQuestion, originalQuestion });
|
// Analyze the answer to determine the appropriate response type
|
||||||
|
const answerLower = answer.toLowerCase().trim();
|
||||||
|
const isNegative = answerLower === 'no' || answerLower === 'nein' || answerLower === 'nope' || answerLower === 'nei';
|
||||||
|
const isDontKnow = answerLower.includes("don't know") || answerLower.includes('weiß nicht') || answerLower.includes('keine ahnung') || answer.trim().length < 3;
|
||||||
|
|
||||||
// Call server API for contextual response
|
let response;
|
||||||
const response = await fetch('/api/respond-to-answer', {
|
|
||||||
|
if (isNegative || isDontKnow) {
|
||||||
|
// For "no" or "don't know" answers, get Socratic guidance questions
|
||||||
|
console.log('📤 Sending guidance request to /api/ask for Socratic questioning');
|
||||||
|
|
||||||
|
const guidancePrompt = this.currentLanguage === 'de'
|
||||||
|
? `Ein Kind hat "${answer}" geantwortet auf die Frage "${currentQuestion}" über das Thema "${originalQuestion}". Führe es durch Socratic Fragen zur Entdeckung, ohne direkte Antworten zu geben.`
|
||||||
|
: `A child answered "${answer}" to the question "${currentQuestion}" about the topic "${originalQuestion}". Guide them through Socratic questions to discovery without giving direct answers.`;
|
||||||
|
|
||||||
|
response = await fetch('/api/ask', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
question: guidancePrompt,
|
||||||
|
language: this.currentLanguage
|
||||||
|
})
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// For substantial answers, acknowledge and validate
|
||||||
|
console.log('📤 Sending validation request to /api/respond-to-answer');
|
||||||
|
|
||||||
|
response = await fetch('/api/respond-to-answer', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -522,13 +593,10 @@ class KidsAIExplorer {
|
|||||||
question: currentQuestion,
|
question: currentQuestion,
|
||||||
originalTopic: originalQuestion,
|
originalTopic: originalQuestion,
|
||||||
language: this.currentLanguage,
|
language: this.currentLanguage,
|
||||||
stepIndex: questionIndex,
|
stepIndex: questionIndex
|
||||||
context: 'guided_learning_conversation',
|
|
||||||
instructions: this.currentLanguage === 'de'
|
|
||||||
? 'Du bist ein geduldiger Lernbegleiter für Kinder. Gib NIEMALS direkte Antworten. Stelle stattdessen Folgefragen, die das Kind zum Nachdenken anregen. Verwende die Sokratische Methode - führe das Kind durch Fragen zur Entdeckung. Sei ermutigend und neugierig.'
|
|
||||||
: 'You are a patient learning companion for children. NEVER give direct answers. Instead, ask follow-up questions that encourage the child to think deeper. Use the Socratic method - guide the child to discovery through questions. Be encouraging and curious.'
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log('📥 Chat server response status:', response.status);
|
console.log('📥 Chat server response status:', response.status);
|
||||||
|
|
||||||
@@ -539,7 +607,25 @@ class KidsAIExplorer {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('✅ Chat server response data:', data);
|
console.log('✅ Chat server response data:', data);
|
||||||
|
|
||||||
if (data.success && data.response) {
|
let responseContent = '';
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
if (data.guidance && data.guidance.steps) {
|
||||||
|
// Response from /api/ask with Socratic guidance steps
|
||||||
|
const steps = data.guidance.steps.slice(0, 3); // Limit to 3 steps
|
||||||
|
responseContent = steps.map((step, index) =>
|
||||||
|
`<p><strong>${index + 1}.</strong> ${step.text}</p>`
|
||||||
|
).join('');
|
||||||
|
} else if (data.response) {
|
||||||
|
// Simple response from /api/respond-to-answer
|
||||||
|
responseContent = `<p>${data.response}</p>`;
|
||||||
|
} else {
|
||||||
|
// Fallback
|
||||||
|
responseContent = this.currentLanguage === 'de'
|
||||||
|
? '<p>🤔 Das ist eine interessante Frage! Lass uns zusammen darüber nachdenken...</p>'
|
||||||
|
: '<p>🤔 That\'s an interesting question! Let\'s think about it together...</p>';
|
||||||
|
}
|
||||||
|
|
||||||
// Add AI response bubble
|
// Add AI response bubble
|
||||||
const responseBubble = document.createElement('div');
|
const responseBubble = document.createElement('div');
|
||||||
responseBubble.className = 'chat-message ai-message';
|
responseBubble.className = 'chat-message ai-message';
|
||||||
@@ -549,7 +635,7 @@ class KidsAIExplorer {
|
|||||||
<span class="ai-label">${this.getTranslation('ai-teacher')}</span>
|
<span class="ai-label">${this.getTranslation('ai-teacher')}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="message-content">
|
<div class="message-content">
|
||||||
<p>${data.response}</p>
|
${responseContent}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user