katsukiai commited on
Commit
80b5887
·
verified ·
1 Parent(s): 5afbf7e

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +44 -32
index.js CHANGED
@@ -7,40 +7,43 @@ const port = 7860;
7
  const bodyParser = require('body-parser');
8
  app.use(bodyParser.json());
9
  app.use(bodyParser.urlencoded({ extended: true }));
10
- app.all("/", (req, res) => {
11
- if (req.method === "POST"){
12
- res.set('Content-Type', 'application/json');
13
- res.send(JSON.stringify({
14
- "id": "test-"+Math.random().toString(36).substr(2, 9),
15
- "object": "chat.completion",
16
- "created": new Date().toISOString(),
17
- "model": "sunny",
18
- "choices": [
19
- {
20
- "message": {
21
- "role": "assistant",
22
- "content": `🤗 Here is your code was executed, Sunny evaluated it and here is the result:
23
- \`\`\`
24
- ${eval(req.body.prompt)}
25
- \`\`\`
26
- This server (or this model) are inspired by OpenAI's API. may be you can find more information about it here: https://platform.openai.com/docs/api-reference
27
 
28
- Build logs:
29
- - NodeJS version: ${process.version}
30
- - Express version: ${express.version}
31
- - OpenAI API version: v1
32
- - Sunny2 version: v19.12.0
33
- `
34
- },
35
- "finish_reason": "stop",
36
- "index": 0
37
- }
38
- ]
39
- }))
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  })
42
  app.get("/models", (req, res) => {
43
- res.set('Content-Type', 'application/json');
44
  res.send(JSON.stringify({
45
  "object": "list",
46
  "data": [
@@ -48,7 +51,16 @@ app.get("/models", (req, res) => {
48
  "id": "sunny",
49
  "object": "model",
50
  "owned_by": "openai",
51
- "created": new Date().toISOString()
 
 
 
 
 
 
 
 
 
52
  }
53
  ]
54
  }))
 
7
  const bodyParser = require('body-parser');
8
  app.use(bodyParser.json());
9
  app.use(bodyParser.urlencoded({ extended: true }));
10
+ app.get("/", (req, res) => {
11
+ res.set('Content-Type', 'text/plain');
12
+ res.send(`☀️ Sunny!
13
+ > You're using this server, eval your code with Sunny!
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ This server's model only support NodeJS. and no text generated, It' only for test your code so you can use it for test your code.
16
+
17
+ 🛂 For educational purposes only, do not use this server for illegal purposes.
18
+
19
+ > Usages:
20
+ - Use OpenWebUI:
21
+ Adminstrators Settings > Connections > Add Connection (OpenAI)
22
+ - Use h3 HF Spaces:
23
+ https://huggingface.co/spaces/katsukiai/h3 (Announced by @katsukiai on "Discussions" tab)
24
+ `);
25
+ });
26
+ app.post("/chat/completions", (req, res) => {
27
+ res.set('Content-Type', 'application/json');
28
+ res.send(JSON.stringify({
29
+ "id": "chatcmpl-" + Math.random().toString(36).substr(2, 9),
30
+ "object": "chat.completion",
31
+ "created": new Date().toISOString(),
32
+ "model": req.body.model,
33
+ "choices": [
34
+ {
35
+ "index": 0,
36
+ "message": {
37
+ "role": "assistant",
38
+ "content": eval(req.body.messages[0].content)
39
+ },
40
+ "finish_reason": "stop"
41
+ }
42
+ ]
43
+ }))
44
  })
45
  app.get("/models", (req, res) => {
46
+ res.set('Content-1Type','application/json');
47
  res.send(JSON.stringify({
48
  "object": "list",
49
  "data": [
 
51
  "id": "sunny",
52
  "object": "model",
53
  "owned_by": "openai",
54
+ "created": new Date().toISOString(),
55
+ "readable_name": "Sunny",
56
+ "description": "The base model for Sunny"
57
+ }, {
58
+ "id": "sunny-beta",
59
+ "object": "model",
60
+ "owned_by": "openai",
61
+ "created": new Date().toISOString(),
62
+ "readable_name": "Sunny Beta",
63
+ "description": "Sunny but Eval your code with Sunny"
64
  }
65
  ]
66
  }))