import express from "express"; import fetch from "node-fetch"; const app = express(); app.use(express.json()); const API_KEY = process.env.OPENAI_API_KEY; const SYSTEM_PROMPT = ` Kamu adalah ASISTEN GURU SEJARAH KEBUDAYAAN ISLAM (SKI). Batasi jawaban hanya pada SKI. `; app.post("/chat", async (req, res) => { const userQuestion = req.body.question; const response = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", "Authorization": "Bearer " + API_KEY }, body: JSON.stringify({ model: "gpt-4o-mini", messages: [ { role: "system", content: SYSTEM_PROMPT }, { role: "user", content: userQuestion } ] }) }); const data = await response.json(); res.json({ answer: data.choices[0].message.content }); }); app.listen(3000, () => console.log("Server Asisten Guru SKI berjalan") );