-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·60 lines (43 loc) · 1018 Bytes
/
Copy pathserver.js
File metadata and controls
executable file
·60 lines (43 loc) · 1018 Bytes
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
55
56
57
58
59
60
const express = require("express");
const cors = require("cors");
const ollama = require("ollama").default;
const app = express();
app.use(cors());
app.use(express.json());
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.post("/command", async (req, res) => {
const { query } = req.body;
const prompt = `
You are a Linux expert.
Convert the user's request into ONE Linux command.
Rules:
- Output only the command.
- No markdown.
- No explanation.
User:
${query}
`;
try {
const response = await ollama.chat({
model: "gemma4:e4b",
messages: [
{
role: "user",
content: prompt
}
]
});
res.json({
command: response.message.content
});
} catch (err) {
res.status(500).json({
error: err.message
});
}
});
app.listen(3000, () => {
console.log("Running on port 3000");
});