katsukiai commited on
Commit
68ceccd
·
verified ·
1 Parent(s): 956ccbc

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +53 -3
index.js CHANGED
@@ -1,12 +1,62 @@
 
 
 
1
  const express = require('express');
2
- const bodyParser = require('body-parser');
3
- const vm = require('vm');
4
-
5
  const app = express();
6
  const port = 7860;
 
 
7
 
8
  app.use(bodyParser.json());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
 
10
  app.post("/chat/completions", async (req, res) => {
11
  const input = req.body?.messages?.[0]?.content || "";
12
  let output = '';
 
1
+ /**
2
+ * Sunny - OpenAI-like API Server for testing NodeJS code
3
+ */
4
  const express = require('express');
 
 
 
5
  const app = express();
6
  const port = 7860;
7
+ const bodyParser = require('body-parser');
8
+ const vm = require('vm');
9
 
10
  app.use(bodyParser.json());
11
+ app.use(bodyParser.urlencoded({ extended: true }));
12
+
13
+ // Root endpoint
14
+ app.get("/", (req, res) => {
15
+ res.set('Content-Type', 'text/plain');
16
+ res.send(`☀️ Sunny!
17
+ > You're using this server to eval your code with Sunny!
18
+
19
+ This server model only supports NodeJS. It doesn't generate text, only executes code for testing.
20
+
21
+ 🛂 For educational purposes only. Do not use this server for illegal activities.
22
+
23
+ > Usage:
24
+ - Use OpenWebUI:
25
+ Administrators Settings > Connections > Add Connection (OpenAI)
26
+ - Use h3 HF Spaces:
27
+ https://huggingface.co/spaces/katsukiai/h3
28
+ `);
29
+ });
30
+
31
+ // /models - Return the models
32
+ app.get("/models", (req, res) => {
33
+ res.set('Content-Type', 'application/json');
34
+ res.send({
35
+ object: "list",
36
+ data: [
37
+ {
38
+ id: "sunny",
39
+ object: "model",
40
+ created: Math.floor(Date.now() / 1000),
41
+ owned_by: "sunny-dev",
42
+ permission: [],
43
+ root: "sunny",
44
+ parent: null
45
+ },
46
+ {
47
+ id: "sunny-beta",
48
+ object: "model",
49
+ created: Math.floor(Date.now() / 1000),
50
+ owned_by: "sunny-dev",
51
+ permission: [],
52
+ root: "sunny-beta",
53
+ parent: null
54
+ }
55
+ ]
56
+ });
57
+ });
58
 
59
+ // /chat/completions - Secure sandboxed code execution
60
  app.post("/chat/completions", async (req, res) => {
61
  const input = req.body?.messages?.[0]?.content || "";
62
  let output = '';