File size: 474 Bytes
3693d04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import express, { json } from "express";
import { encode } from "gpt-3-encoder";

const app = express();
const port = 7860;

app.use(json());

app.post('*', (req, res) => {
    const { text } = req.body;
    const encoded = encode(text);
    const length = encoded.length;

    res.send({ length });
});

app.use((req, res) => {
    res.status(405).send({ error: "Method not allowed" });
});

app.listen(port, () => {
    console.log(`Server listening on port ${port}`);
});