Update api/index.js
Browse files- api/index.js +11 -6
api/index.js
CHANGED
@@ -63,15 +63,19 @@ const withAuth = (request) => {
|
|
63 |
const logger = (res, req) => {
|
64 |
console.log(req.method, res.status, req.url, Date.now() - req.start, 'ms');
|
65 |
};
|
|
|
66 |
const router = AutoRouter({
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
});
|
71 |
-
|
|
|
72 |
router.get('/', () => json({ message: 'API 服务运行中~' }));
|
73 |
router.get('/ping', () => json({ message: 'pong' }));
|
74 |
-
|
|
|
|
|
75 |
json({
|
76 |
object: 'list',
|
77 |
data: [
|
@@ -91,7 +95,8 @@ router.get(config.API_PREFIX + '/v1/models', () =>
|
|
91 |
],
|
92 |
})
|
93 |
);
|
94 |
-
|
|
|
95 |
|
96 |
async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
|
97 |
// 在非GPT类型的模型中,temperature和top_p是无效的
|
|
|
63 |
const logger = (res, req) => {
|
64 |
console.log(req.method, res.status, req.url, Date.now() - req.start, 'ms');
|
65 |
};
|
66 |
+
|
67 |
const router = AutoRouter({
|
68 |
+
before: [preflight], // 只保留 CORS preflight 检查
|
69 |
+
missing: () => error(404, '404 not found.'),
|
70 |
+
finally: [corsify, logger],
|
71 |
});
|
72 |
+
|
73 |
+
// 不需要验证的路由
|
74 |
router.get('/', () => json({ message: 'API 服务运行中~' }));
|
75 |
router.get('/ping', () => json({ message: 'pong' }));
|
76 |
+
|
77 |
+
// 需要验证的路由单独添加 withAuth 中间件
|
78 |
+
router.get(config.API_PREFIX + '/v1/models', withAuth, () =>
|
79 |
json({
|
80 |
object: 'list',
|
81 |
data: [
|
|
|
95 |
],
|
96 |
})
|
97 |
);
|
98 |
+
|
99 |
+
router.post(config.API_PREFIX + '/v1/chat/completions', withAuth, (req) => handleCompletion(req));
|
100 |
|
101 |
async function GrpcToPieces(models, message, rules, stream, temperature, top_p) {
|
102 |
// 在非GPT类型的模型中,temperature和top_p是无效的
|