reply fields added
This commit is contained in:
@@ -251,7 +251,7 @@ app.post('/api/thinking-feedback', async (req, res) => {
|
||||
|
||||
try {
|
||||
// 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({
|
||||
success: true,
|
||||
@@ -834,13 +834,73 @@ function getFallbackMathHints(question, language) {
|
||||
async function getThinkingFeedback(question, thought, stepNumber, language) {
|
||||
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
|
||||
? "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."
|
||||
: "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.";
|
||||
? `Du bist ein intelligenter Tutor für Kinder. Ein Kind hat auf eine Denkfrage geantwortet. Deine Aufgabe:
|
||||
|
||||
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
|
||||
? `Frage: "${question}"\nSchritt ${stepNumber}\nKind dachte: "${thought}"\n\nGib eine kurze, ermutigende Rückmeldung zu diesem Gedanken.`
|
||||
: `Question: "${question}"\nStep ${stepNumber}\nChild thought: "${thought}"\n\nGive brief, encouraging feedback about this thought.`;
|
||||
? `Original Frage: "${question}"
|
||||
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 {
|
||||
const completion = await openai.chat.completions.create({
|
||||
@@ -849,22 +909,23 @@ async function getThinkingFeedback(question, thought, stepNumber, language) {
|
||||
{ role: "system", content: systemPrompt },
|
||||
{ role: "user", content: userPrompt }
|
||||
],
|
||||
max_tokens: 100,
|
||||
temperature: 0.7
|
||||
max_tokens: 120,
|
||||
temperature: 0.8
|
||||
});
|
||||
|
||||
const aiResponse = completion.choices[0]?.message?.content || '';
|
||||
|
||||
// Determine feedback type based on content
|
||||
const responseType = aiResponse.toLowerCase().includes('gut') ||
|
||||
aiResponse.toLowerCase().includes('great') ||
|
||||
aiResponse.toLowerCase().includes('good') ||
|
||||
aiResponse.toLowerCase().includes('richtig')
|
||||
? 'positive' : 'neutral';
|
||||
// Determine feedback type based on content and child's response quality
|
||||
let responseType = 'neutral';
|
||||
if (thoughtLower.length > 10 || thoughtLower.includes('because') || thoughtLower.includes('weil')) {
|
||||
responseType = 'positive';
|
||||
} else if (thoughtLower.length < 5) {
|
||||
responseType = 'encouraging';
|
||||
}
|
||||
|
||||
return {
|
||||
response: aiResponse.trim(),
|
||||
encouragement: isGerman ? "Weiter so! 🌟" : "Keep going! 🌟",
|
||||
encouragement: isGerman ? "Du denkst gut mit! 🧠" : "You're thinking well! 🧠",
|
||||
type: responseType,
|
||||
source: 'OpenAI GPT-3.5'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user