forked from keldenl/gpt-llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (70 loc) · 1.53 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import express from 'express';
import cors from 'cors';
import IP from 'ip';
import swaggerJsdoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import modelsRoutes from './routes/modelsRoutes.js';
import chatRoutes from './routes/chatRoutes.js';
import embeddingsRoutes from './routes/embeddingsRoutes.js';
const PORT = 443;
const options = {
definition: {
openapi: '3.0.1',
info: {
title: 'gpt-llama.cpp',
version: '1.0.0',
description: 'Use llama.cpp in place of the OpenAi GPT API',
license: {
name: 'MIT',
url: 'https://spdx.org/licenses/MIT.html',
},
contact: {
name: 'Kelden',
url: 'https://github.com/keldenl',
},
},
basePath: '/',
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
},
security: [
{
bearerAuth: [],
},
],
servers: [
{
url: `http://localhost:${PORT}`,
},
],
},
apis: ['./routes/*.js'],
};
const specs = swaggerJsdoc(options);
global.childProcess = undefined;
global.lastRequest = undefined;
const app = express();
app.use(cors());
app.use(express.json());
app.use(
'/docs',
swaggerUi.serve,
swaggerUi.setup(specs, {
explorer: true,
})
);
app.use('/v1/models', modelsRoutes);
app.use('/v1/chat', chatRoutes);
app.use('/v1/embeddings', embeddingsRoutes);
app.listen(PORT, () => {
const ipAddress = IP.address();
console.log(`Server is listening on:
- localhost:${PORT}
- ${ipAddress}:${PORT} (for other devices on the same network)`);
});