File size: 1,114 Bytes
5cd6458
 
 
 
 
3e7e8b4
 
5cd6458
 
 
3e7e8b4
5cd6458
 
 
3e7e8b4
 
 
a9a4246
3e7e8b4
 
5cd6458
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require('dotenv').config();

const express = require('express');
const bearerToken = require('express-bearer-token');
const openai = require('./openai');
const { stats } = require('./utils');
const config = require('./config.json');

const app = express();
const port = 7860;
const started = new Date();

app.get('/', (req, res) => {
    res.json({
        uptime: (new Date() - started) / 1000,
        slacks: config.slacks.length || 0,
        prompts: stats.prompts.length || 0,
        avgTime: (stats.prompts.reduce((acc, curr) => acc + curr.time, 0) / stats.prompts.length || 0) / 1000,
        avgInputLength: stats.prompts.reduce((acc, curr) => acc + curr.inputLength, 0) / stats.prompts.length || 0,
        avgOutputLength: stats.prompts.reduce((acc, curr) => acc + curr.outputLength, 0) / stats.prompts.length || 0,
    });
})

app.use('/v1', bearerToken({
    bodyKey: false,
    queryKey: false,
    headerKey: 'Bearer',
    reqKey: false,
    cookie: false, // by default is disabled
}), openai);

app.listen(port, () => {
    console.log(`Claude proxy listening on http://127.0.0.1:${port}/`);
});