Spaces:
Sleeping
Sleeping
more feature-complete app
Browse filesFiles changed (3)
- .prettierrcAdded+3
- .vscode/settings.json+2-1
- server.ts+29-4
123{ "useTabs": true}123{"editor.formatOnSave": true}1234{"editor.formatOnSave": true,"editor.defaultFormatter": "esbenp.prettier-vscode",}
123452 unmodified lines8910111213141516171819202122232425import * as express from "express";const app = express();// parse HTTP request bodies as jsonapp.use(express.json());2 unmodified linesres.json({ hello: "world" });});app.post("/", (req, res) => {if (req.header("X-Webhook-Secret") !== process.env.WEBHOOK_SECRET) {return res.status(400).json({ error: "incorrect secret" });}console.log(req.body);res.json({ success: true });});const PORT = 7860;app.listen(PORT, () => {console.debug(`server started at http://localhost:${PORT}`);});12345678910112 unmodified lines14151617181920212223242526272829303132333435363738394041424344454647484950import * as express from "express";const PORT = 7860;const BOT_USERNAME = "@discussion-bot";const INFERENCE_URL ="https://api-inference.huggingface.co/models/bigscience/bloom";const PROMPT = `Pretend that you are a bot that replies to discussions about machine learning, and reply to the following comment:\n`;const app = express();// parse HTTP request bodies as jsonapp.use(express.json());2 unmodified linesres.json({ hello: "world" });});app.post("/", async (req, res) => {if (req.header("X-Webhook-Secret") !== process.env.WEBHOOK_SECRET) {return res.status(400).json({ error: "incorrect secret" });}console.log(req.body);const event = req.body.event;if (event.action === "create" &&event.scope === "discussion.comment" &&req.body.comment.content.includes(BOT_USERNAME)) {const response = await fetch(INFERENCE_URL, {method: "POST",body: JSON.stringify({ inputs: PROMPT + req.body.comment.content }),});if (response.ok) {const output = await response.json();const continuationText = output[0].generated_text.replace(PROMPT + req.body.comment.content,"");console.log(continuationText);/// Finally, let's post it as a comment in the same discussion} else {console.error(`API Error`, await response.json());}}res.json({ success: true });});app.listen(PORT, () => {console.debug(`server started at http://localhost:${PORT}`);});
.prettierrcAdded+3
.vscode/settings.json+2-1
server.ts+29-4