-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.js
More file actions
45 lines (37 loc) · 1.34 KB
/
main.js
File metadata and controls
45 lines (37 loc) · 1.34 KB
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
const express = require('express');
const bodyParser = require('body-parser');
const config = require('config');
const Proxy = require('./proxy/proxy');
const app = express();
app.use(bodyParser.json());
const _serverConfig = config.get('server');
const serverConfig = {
host: _serverConfig.host, // 该服务监听的ip
port: _serverConfig.port // 该服务监听的端口
};
const target = process.env.PROXY_TARGET || _serverConfig.target;
app.post('/api/v1/retrieval', async (req, res) => {
console.log("Use Target", target);
console.log(req.headers.authorization);
console.log(req.body);
// 根据target配置, 生成一个proxy对象 <Promise>
const query = new Proxy(target, {
knowledge_id: req.body.knowledge_id,
authorization: req.headers.authorization,
query: req.body.query,
top_k: req.body.retrieval_setting.top_k,
score: req.body.retrieval_setting.score_threshold
});
// 等待proxy对象返回结果, 并返回给用户
query
.then((response) => {
res.json(response);
})
.catch((error) => {
console.error(error);
res.status(500).json(error);
});
});
app.listen(serverConfig.port, serverConfig.host, () => {
console.log(`Server running at http://${serverConfig.host}:${serverConfig.port}/`);
});