katsukiai commited on
Commit
d10a0b0
·
verified ·
1 Parent(s): a9f4dd2

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +56 -0
app.js ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Sunny - OpenAI-like API Server for test your code (only NODEJS)
3
+ */
4
+ const express = require('express');
5
+ const app = express();
6
+ const port = 3000;
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": [
47
+ {
48
+ "id": "sunny",
49
+ "object": "model",
50
+ "owned_by": "openai",
51
+ "created": new Date().toISOString()
52
+ }
53
+ ]
54
+ }))
55
+ })
56
+ app.listen(port, () => console.log(`Sunny listening on port ${port}!`))