-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (49 loc) · 1.23 KB
/
index.js
File metadata and controls
62 lines (49 loc) · 1.23 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
55
56
57
58
59
60
61
62
import express from "express";
import Replicate from "replicate";
const app = express();
const replicate = new Replicate({
auth: process.env.REPLICATE_API_KEY,
});
app.use(express.json());
app.post("/generate", async (req, res) => {
const { prompt } = req.body;
if (!prompt) {
return res.status(400).json({ error: "Prompt is required" });
}
const input = {
cfg: 4.5,
prompt,
aspect_ratio: "1:1",
output_format: "webp",
output_quality: 79,
negative_prompt: "ugly, distorted",
};
const output = await replicate.run("stability-ai/stable-diffusion-3", {
input,
});
console.log(output);
res.json(output);
});
app.post("/chat", async (req, res) => {
const { prompt } = req.body;
const input = {
top_k: 0,
top_p: 0.9,
prompt,
temperature: 0.6,
length_penalty: 1,
max_new_tokens: 128,
prompt_template: "{prompt}",
presence_penalty: 1.15,
};
for await (const event of replicate.stream("meta/meta-llama-3-8b", {
input,
})) {
// process.stdout.write(event.toString());
res.write(event.toString());
}
res.end()
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});