🧠 Enhance deeper exploration and fix validation responses

- Fixed /api/explore-deeper to use OpenAI for contextual Socratic questions instead of generic random prompts
- Added proper system prompts that focus on asking single, thoughtful follow-up questions
- Updated fallback prompts to be complete, engaging questions that encourage hands-on exploration
- Fixed /api/respond-to-answer to provide ONLY encouragement without giving explanations or facts
- Clarified prompts to prevent AI from revealing answers during validation responses
- Improved Socratic teaching approach for 'Tell me more' deeper exploration

This ensures both validation responses and deeper exploration maintain pure Socratic methodology.
This commit is contained in:
root
2025-06-30 12:35:05 +02:00
parent b7c7bbfcb1
commit d316e3ceca

View File

@@ -561,30 +561,36 @@ app.post('/api/respond-to-answer', async (req, res) => {
const isGerman = language === 'de';
const contextualPrompt = isGerman ?
`Du bist ein pädagogischer KI-Assistent für Kinder. Ein Kind hat gerade auf eine Frage geantwortet.
`Du bist ein unterstützender Lernbegleiter für Kinder. Ein Kind hat gerade auf eine Frage geantwortet.
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
4. Verwende Emojis sparsam und altersgerecht
Deine Aufgabe ist es, eine rein ermutigende Antwort zu geben, die:
1. Das Kind für seinen Mut zu antworten lobt
2. Die spezifische Antwort wertschätzt
3. Das Nachdenken des Kindes würdigt
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.
WICHTIG:
- Gib KEINE Erklärungen oder Fakten
- Stelle KEINE Folgefragen
- Verrate NICHT die richtige Antwort
- Antworte nur mit Ermutigung und Anerkennung in 1-2 kurzen Sätzen` :
`You are a supportive learning companion for children. A child just answered a question.
QUESTION: "${question}"
CHILD'S ANSWER: "${answer}"
Your task is to provide an encouraging, educational response that:
1. Encourages the child for their answer (regardless of right or wrong)
2. Builds on their specific answer
3. Acknowledges and expands their thinking
4. Use emojis sparingly and age-appropriately
Your task is to provide a purely encouraging response that:
1. Praises the child for having the courage to answer
2. Appreciates their specific answer
3. Acknowledges the child's thinking
IMPORTANT: Do NOT ask follow-up questions - only respond with encouragement and validation in 1-2 sentences.`;
IMPORTANT:
- Give NO explanations or facts
- Ask NO follow-up questions
- Do NOT reveal the correct answer
- Only respond with encouragement and recognition in 1-2 short sentences`;
// Try OpenAI first
if (process.env.OPENAI_API_KEY) {
@@ -652,7 +658,7 @@ IMPORTANT: Do NOT ask follow-up questions - only respond with encouragement and
// API endpoint for deeper exploration of current topic
app.post('/api/explore-deeper', async (req, res) => {
try {
const { question, userAnswer, language = 'en', context } = req.body;
const { question, userAnswer, language = 'en', context, instructions } = req.body;
if (!question) {
return res.status(400).json({
@@ -664,29 +670,71 @@ app.post('/api/explore-deeper', async (req, res) => {
console.log(`🔍 Generating deeper exploration for: "${question}" with user answer: "${userAnswer}"`);
const isGerman = language === 'de';
// Try OpenAI first for contextual deeper exploration
if (process.env.OPENAI_API_KEY) {
try {
const systemPrompt = isGerman
? "Du bist ein neugieriger Lernbegleiter für Kinder. Ein Kind hat gerade eine Antwort auf eine Frage gegeben. Deine Aufgabe ist es, eine faszinierende Folgefrage zu stellen, die das Kind dazu bringt, noch tiefer über das Thema nachzudenken. GEBE NIEMALS DIREKTE ANTWORTEN! Stelle stattdessen eine einzige, durchdachte Frage, die das Kind zu weiterer Entdeckung einlädt. Verwende Sätze wie 'Hast du schon mal bemerkt...?', 'Was würde passieren, wenn...?', 'Was denkst du, warum...?' oder 'Kannst du dir vorstellen...?'. Ermutige zur Beobachtung und zum eigenen Experimentieren."
: "You are a curious learning companion for children. A child just gave an answer to a question. Your task is to ask a fascinating follow-up question that makes the child think even deeper about the topic. NEVER give direct answers! Instead, ask one thoughtful question that invites the child to further discovery. Use phrases like 'Have you ever noticed...?', 'What would happen if...?', 'What do you think would...?' or 'Can you imagine...?'. Encourage observation and hands-on exploration.";
const userPrompt = isGerman
? `URSPRÜNGLICHE FRAGE: "${question}"
ANTWORT DES KINDES: "${userAnswer}"
Stelle eine durchdachte Folgefrage, die das Kind dazu einlädt, das Thema tiefer zu erforschen. Die Frage sollte neugierig machen und zur eigenen Beobachtung ermutigen. Gib KEINE Antworten - nur eine einzige, faszinierende Frage.`
: `ORIGINAL QUESTION: "${question}"
CHILD'S ANSWER: "${userAnswer}"
Ask one thoughtful follow-up question that invites the child to explore the topic deeper. The question should spark curiosity and encourage hands-on observation. Give NO answers - just one fascinating question.`;
const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{ role: "system", content: systemPrompt },
{ role: "user", content: userPrompt }
],
max_tokens: 150,
temperature: 0.8
});
const aiResponse = completion.choices[0]?.message?.content?.trim();
if (aiResponse && aiResponse.length > 10) {
console.log('✅ OpenAI deeper exploration generated successfully');
return res.json({
success: true,
response: aiResponse,
source: 'OpenAI GPT-3.5 Deeper Exploration'
});
}
} catch (openaiError) {
console.log('❌ OpenAI error for deeper exploration:', openaiError.message);
}
}
// Generate deeper exploration prompts
// Fallback: Generate contextual deeper exploration prompts based on the topic
const deeperExplorationPrompts = isGerman ? [
`🔬 Das ist wirklich faszinierend! Wusstest du, dass es noch viel mehr zu entdecken gibt? Was denkst du passiert, wenn...?`,
`💡 Super Antwort! Lass uns tiefer graben. Hast du dich schon mal gefragt, warum das so funktioniert?`,
`🌟 Excellent! Das bringt mich auf eine weitere interessante Frage: Wie könnte das in der echten Welt verwendet werden?`,
`🎯 Du denkst wie ein echter Wissenschaftler! Was würde passieren, wenn wir das Experiment anders machen würden?`,
`🔍 Das ist ein großartiger Punkt! Kennst du andere Beispiele, wo das Gleiche passiert?`
`🔬 Spannend! Hast du schon mal versucht, das selbst zu beobachten? Was würdest du erwarten zu sehen?`,
`💡 Das ist eine gute Überlegung! Was denkst du, würde passieren, wenn du das Experiment zu Hause nachmachen würdest?`,
`🌟 Interessant! Kannst du dir vorstellen, wo du so etwas in der Natur noch beobachten könntest?`,
`<EFBFBD> Du denkst wirklich gut nach! Hast du schon mal bemerkt, ob das bei verschiedenen Wetterbedingungen anders ist?`,
`🔍 Das ist ein großartiger Punkt! Was würde passieren, wenn du versuchst, das mit verschiedenen Materialien zu testen?`
] : [
`🔬 That's really fascinating! Did you know there's even more to discover? What do you think happens when...?`,
`💡 Great answer! Let's dig deeper. Have you ever wondered why it works that way?`,
`🌟 Excellent! That brings up another interesting question: How might this be used in the real world?`,
`🎯 You're thinking like a real scientist! What would happen if we did the experiment differently?`,
`🔍 That's a great point! Do you know other examples where the same thing happens?`
`🔬 Fascinating! Have you ever tried observing this yourself? What would you expect to see?`,
`💡 That's good thinking! What do you think would happen if you tried this experiment at home?`,
`🌟 Interesting! Can you imagine where else you might observe this in nature?`,
`🎯 You're really thinking well! Have you ever noticed if this looks different in various weather conditions?`,
`🔍 That's a great point! What would happen if you tried testing this with different materials?`
];
// Select a random deeper exploration prompt
// Select a random contextual deeper exploration prompt
const randomPrompt = deeperExplorationPrompts[Math.floor(Math.random() * deeperExplorationPrompts.length)];
res.json({
success: true,
response: randomPrompt,
source: 'Deeper Exploration',
source: 'Contextual Deeper Exploration Fallback',
context: 'exploration'
});