-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (47 loc) · 1.3 KB
/
Copy pathserver.js
File metadata and controls
54 lines (47 loc) · 1.3 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
50
51
52
53
54
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import axios from "axios";
dotenv.config();
const app = express();
const PORT = 5000;
app.use(cors());
app.use(express.json());
app.post("/api/generate", async (req, res) => {
const { prompt } = req.body;
try {
const response = await axios.post(
"https://api.groq.com/openai/v1/chat/completions",
{
model: "llama3-70b-8192",
messages: [
{
role: "system",
content:
"You are a legal expert simulating both sides of a courtroom case. Provide separate arguments for the prosecution and the defense."
},
{
role: "user",
content: prompt
}
],
temperature: 0.7
},
{
headers: {
Authorization: `Bearer ${process.env.GROQ_API_KEY}`,
"Content-Type": "application/json"
}
}
);
res.json({ output: response.data.choices[0].message.content });
} catch (error) {
console.error("Groq error:", error.response?.data || error.message);
res.status(500).json({
error: error.response?.data?.error?.message || "Unknown error"
});
}
});
app.listen(PORT, () => {
console.log(`Server listening on http://localhost:${PORT}`);
});