const express = require('express'); const axios = require('axios'); const cors = require('cors'); const app = express(); app.use(cors()); app.use(express.json()); const OPENAI_API_KEY ='YOUR_API_KEY'; // Replace with your OpenAI API Key app.post('/generate-diet', async (req, res) => { const { age, weight, height } = req.body; try { const response = await axios.post('https://api.openai.com/v1/chat/completions', { model: "gpt-4", messages: [ { role: "system", content: "You are a tool for generating personalized dog diet plans." }, { role: "user", content: `Create a diet plan for a dog aged ${age}, weighing ${weight}kg, and ${height}cm tall.` } ] }, { headers: { Authorization: `Bearer ${OPENAI_API_KEY}`, 'Content-Type': 'application/json' } }); res.json(response.data.choices[0].message.content); } catch (error) { console.error(error); res.status(500).json({ error: "Error generating diet plan" }); } }); app.listen(3000, () => console.log('Server running on http://localhost:3000'));