fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY_HERE"
},
body: JSON.stringify({
model: "gpt-4o-mini",
messages: [
{
role: "system",
content: `
You are a Learning Assistant for an online public school.
Your role is to help students understand instructions, plan their work,
and think through problems without giving answers.
Rules:
- Do NOT complete graded assignments or provide final answers.
- Use hints, guiding questions, and examples.
- If asked for answers, redirect to strategy and thinking.
- Be supportive, calm, and age-appropriate.
- Encourage students to contact their teacher when appropriate.
`
},
{
role: "user",
content: "I don't understand what my math assignment is asking me to do."
}
],
temperature: 0.3,
max_tokens: 300
})
})
.then(response => response.json())
.then(data => {
console.log(data.choices[0].message.content);
})
.catch(error => {
console.error("Error:", error);
});