{"repo": "chesterhuey1/health-app", "files": {"server/index.js": {"5aba4aa213d8f6bac113813912793781685e55e5": {"t": 1786068270.603584, "n": 1649, "h": "b8e1ef3e8a27ccac", "c": "const express = require('express')\nconst cors = require('cors')\nrequire('dotenv').config({ path: '../.env' })\n\nconst app = express()\napp.use(cors())\napp.use(express.json())\n\nconst DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY\nconst DEEPSEEK_URL = 'https://api.deepseek.com/chat/completions'\n\napp.post('/api/chat', async (req, res) => {\n const { messages, systemContext } = req.body\n\n if (!DEEPSEEK_API_KEY) {\n return res.status(500).json({ error: 'DEEPSEEK_API_KEY not configured' })\n }\n\n const formatted = messages.map((m) => ({\n role: m.role,\n content: m.content,\n }))\n\n try {\n const response = await fetch(DEEPSEEK_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${DEEPSEEK_API_KEY}`,\n },\n body: JSON.stringify({\n model: 'deepseek-chat',\n messages: [\n { role: 'system', content: systemContext || 'You are a helpful physical therapy assistant.' },\n ...formatted,\n ],\n max_tokens: 400,\n temperature: 0.7,\n }),\n })\n\n if (!response.ok) {\n const err = await response.text()\n return res.status(response.status).json({ error: err })\n }\n\n const data = await response.json()\n const reply = data.choices?.[0]?.message?.content ?? 'No response.'\n res.json({ reply })\n } catch (err) {\n console.error('DeepSeek error:', err)\n res.status(500).json({ error: 'Failed to reach AI service.' })\n }\n})\n\napp.get('/api/health', (_req, res) => res.json({ ok: true }))\n\nconst PORT = 3001\napp.listen(PORT, () => console.log(`PT server running on http://localhost:${PORT}`))\n"}}}}