reply fields added

This commit is contained in:
root
2025-06-29 13:30:27 +02:00
parent 81d0da91c2
commit c33f444704

View File

@@ -251,7 +251,7 @@ app.post('/api/thinking-feedback', async (req, res) => {
try { try {
// Get AI feedback on the child's thinking // Get AI feedback on the child's thinking
const feedback = await getThinkingFeedback(question, stepNumber, userThought, language); const feedback = await getThinkingFeedback(question, userThought, stepNumber, language);
res.json({ res.json({
success: true, success: true,
@@ -834,13 +834,73 @@ function getFallbackMathHints(question, language) {
async function getThinkingFeedback(question, thought, stepNumber, language) { async function getThinkingFeedback(question, thought, stepNumber, language) {
const isGerman = language === 'de'; const isGerman = language === 'de';
// Analyze the child's response to provide intelligent feedback
const thoughtLower = thought.toLowerCase().trim();
// Handle special cases first
if (thoughtLower === '' || thoughtLower.length < 2) {
return {
response: isGerman ? "Erzähl mir mehr über deine Gedanken!" : "Tell me more about your thoughts!",
encouragement: isGerman ? "Jede Idee zählt! 💭" : "Every idea counts! 💭",
type: 'encouraging',
source: 'Rule-based'
};
}
if (thoughtLower === 'i dont know' || thoughtLower === 'i don\'t know' || thoughtLower === 'ich weiß nicht' || thoughtLower === 'weiß nicht') {
return {
response: isGerman ?
"Das ist okay! Lass uns gemeinsam überlegen. Was fällt dir als erstes ein, wenn du an diese Frage denkst?" :
"That's okay! Let's think together. What's the first thing that comes to mind when you think about this question?",
encouragement: isGerman ? "Gemeinsam finden wir eine Antwort! 🤝" : "Together we'll find an answer! 🤝",
type: 'supportive',
source: 'Rule-based'
};
}
if (thoughtLower === 'no' || thoughtLower === 'nein' || thoughtLower === 'ja' || thoughtLower === 'yes') {
return {
response: isGerman ?
"Interessant! Kannst du mir mehr darüber erzählen, warum du so denkst?" :
"Interesting! Can you tell me more about why you think that?",
encouragement: isGerman ? "Deine Meinung ist wichtig! 💬" : "Your opinion matters! 💬",
type: 'probing',
source: 'Rule-based'
};
}
// For substantial responses, use AI with much better prompts
const systemPrompt = isGerman const systemPrompt = isGerman
? "Du bist ein ermutigender Tutor für Kinder. Ein Kind hat zu einer Denkfrage geantwortet. Gib eine kurze, positive Rückmeldung (1-2 Sätze) zu seinem Gedanken. Sei ermutigend, auch wenn die Antwort nicht perfekt ist. Erkenne gute Ansätze an und gib sanfte Hinweise für Verbesserungen." ? `Du bist ein intelligenter Tutor für Kinder. Ein Kind hat auf eine Denkfrage geantwortet. Deine Aufgabe:
: "You are an encouraging tutor for children. A child has responded to a thinking question. Give brief, positive feedback (1-2 sentences) about their thought. Be encouraging even if the answer isn't perfect. Acknowledge good approaches and give gentle hints for improvements.";
1. ANALYSIERE den Gedanken des Kindes sorgfältig
2. ERKENNE richtige Ansätze und baue darauf auf
3. KORRIGIERE sanft Missverständnisse ohne die Antwort zu verraten
4. STELLE eine Nachfrage, die das Denken vertieft
5. SEI spezifisch, nicht generisch
Antworte in 1-2 Sätzen. Vermeide generische Phrasen wie "Gut gemacht!" oder "Weiter so!"`
: `You are an intelligent tutor for children. A child has responded to a thinking question. Your job:
1. ANALYZE the child's thought carefully
2. RECOGNIZE correct approaches and build on them
3. GENTLY correct misunderstandings without revealing the answer
4. ASK a follow-up question that deepens thinking
5. BE specific, not generic
Respond in 1-2 sentences. Avoid generic phrases like "Good job!" or "Keep going!"`;
const userPrompt = isGerman const userPrompt = isGerman
? `Frage: "${question}"\nSchritt ${stepNumber}\nKind dachte: "${thought}"\n\nGib eine kurze, ermutigende Rückmeldung zu diesem Gedanken.` ? `Original Frage: "${question}"
: `Question: "${question}"\nStep ${stepNumber}\nChild thought: "${thought}"\n\nGive brief, encouraging feedback about this thought.`; Schritt ${stepNumber}
Kind antwortete: "${thought}"
Gib intelligente, spezifische Rückmeldung zu diesem Gedanken. Baue auf richtigen Ansätzen auf oder korrigiere sanft Missverständnisse. Stelle eine durchdachte Nachfrage.`
: `Original Question: "${question}"
Step ${stepNumber}
Child responded: "${thought}"
Give intelligent, specific feedback about this thought. Build on correct approaches or gently correct misunderstandings. Ask a thoughtful follow-up question.`;
try { try {
const completion = await openai.chat.completions.create({ const completion = await openai.chat.completions.create({
@@ -849,22 +909,23 @@ async function getThinkingFeedback(question, thought, stepNumber, language) {
{ role: "system", content: systemPrompt }, { role: "system", content: systemPrompt },
{ role: "user", content: userPrompt } { role: "user", content: userPrompt }
], ],
max_tokens: 100, max_tokens: 120,
temperature: 0.7 temperature: 0.8
}); });
const aiResponse = completion.choices[0]?.message?.content || ''; const aiResponse = completion.choices[0]?.message?.content || '';
// Determine feedback type based on content // Determine feedback type based on content and child's response quality
const responseType = aiResponse.toLowerCase().includes('gut') || let responseType = 'neutral';
aiResponse.toLowerCase().includes('great') || if (thoughtLower.length > 10 || thoughtLower.includes('because') || thoughtLower.includes('weil')) {
aiResponse.toLowerCase().includes('good') || responseType = 'positive';
aiResponse.toLowerCase().includes('richtig') } else if (thoughtLower.length < 5) {
? 'positive' : 'neutral'; responseType = 'encouraging';
}
return { return {
response: aiResponse.trim(), response: aiResponse.trim(),
encouragement: isGerman ? "Weiter so! 🌟" : "Keep going! 🌟", encouragement: isGerman ? "Du denkst gut mit! 🧠" : "You're thinking well! 🧠",
type: responseType, type: responseType,
source: 'OpenAI GPT-3.5' source: 'OpenAI GPT-3.5'
}; };