|
|
|
|
|
|
|
const express = require('express'); |
|
const app = express(); |
|
const port = 3000; |
|
const bodyParser = require('body-parser'); |
|
app.use(bodyParser.json()); |
|
app.use(bodyParser.urlencoded({ extended: true })); |
|
app.all("/", (req, res) => { |
|
if (req.method === "POST"){ |
|
res.set('Content-Type', 'application/json'); |
|
res.send(JSON.stringify({ |
|
"id": "test-"+Math.random().toString(36).substr(2, 9), |
|
"object": "chat.completion", |
|
"created": new Date().toISOString(), |
|
"model": "sunny", |
|
"choices": [ |
|
{ |
|
"message": { |
|
"role": "assistant", |
|
"content": `π€ Here is your code was executed, Sunny evaluated it and here is the result: |
|
\`\`\` |
|
${eval(req.body.prompt)} |
|
\`\`\` |
|
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 |
|
|
|
Build logs: |
|
- NodeJS version: ${process.version} |
|
- Express version: ${express.version} |
|
- OpenAI API version: v1 |
|
- Sunny2 version: v19.12.0 |
|
` |
|
}, |
|
"finish_reason": "stop", |
|
"index": 0 |
|
} |
|
] |
|
})) |
|
} |
|
}) |
|
app.get("/models", (req, res) => { |
|
res.set('Content-Type', 'application/json'); |
|
res.send(JSON.stringify({ |
|
"object": "list", |
|
"data": [ |
|
{ |
|
"id": "sunny", |
|
"object": "model", |
|
"owned_by": "openai", |
|
"created": new Date().toISOString() |
|
} |
|
] |
|
})) |
|
}) |
|
app.listen(port, () => console.log(`Sunny listening on port ${port}!`)) |