-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (43 loc) · 1.36 KB
/
server.js
File metadata and controls
49 lines (43 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express = require('express');
const cors = require('cors');
const axios = require('axios');
const path = require('path');
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.static('public')); // ✅ serve frontend
const TOGETHER_API_KEY = process.env.TOGETHER_API_KEY;
app.post('/api/chat', async (req, res) => {
const { message, model = "mistralai/Mistral-7B-Instruct-v0.2", persona = "You are a helpful assistant." } = req.body;
try {
const response = await axios.post(
"https://api.together.xyz/inference",
{
model,
messages: [
{ role: "system", content: persona },
{ role: "user", content: message }
],
temperature: 0.7
},
{
headers: {
Authorization: `Bearer ${TOGETHER_API_KEY}`,
'Content-Type': 'application/json'
}
}
);
res.json(response.data);
} catch (err) {
console.error("TOGETHER API ERROR:", err.response?.data || err.message);
res.status(500).json({ error: "Together API request failed", details: err.response?.data });
}
});
// ✅ Fallback to frontend
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
});
const PORT = process.env.PORT || 10000;
app.listen(PORT, () => {
console.log(`✅ BloggyBot server running on http://localhost:${PORT}`);
});