vue2server7 7.0.61 → 7.0.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/test/2.txt +17 -90
package/package.json
CHANGED
package/test/2.txt
CHANGED
|
@@ -1,107 +1,34 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
|
|
4
|
-
const app = express();
|
|
5
|
-
app.use(express.json());
|
|
6
|
-
|
|
7
|
-
// 👉 你的真实接口
|
|
8
|
-
const TARGET_URL =
|
|
9
|
-
"http://maasapp.aip.bj.bob.test:8080/apis/ais-v2/chat/completions";
|
|
10
|
-
|
|
11
|
-
// 👉 公共请求头
|
|
12
|
-
const BASE_HEADERS = {
|
|
13
|
-
Authorization: "Bearer sk-xxx",
|
|
14
|
-
"X-LLM-Application-Tag": "proxyai",
|
|
15
|
-
"Content-Type": "application/json"
|
|
16
|
-
};
|
|
17
|
-
|
|
18
1
|
app.post("/v1/chat/completions", async (req, res) => {
|
|
19
|
-
const { stream = false } = req.body;
|
|
20
|
-
|
|
21
2
|
try {
|
|
22
|
-
|
|
23
|
-
// 🚀 流式模式(SSE)
|
|
24
|
-
// =========================
|
|
25
|
-
if (stream) {
|
|
26
|
-
const response = await axios({
|
|
27
|
-
method: "post",
|
|
28
|
-
url: TARGET_URL,
|
|
29
|
-
data: {
|
|
30
|
-
...req.body,
|
|
31
|
-
stream: true
|
|
32
|
-
},
|
|
33
|
-
headers: BASE_HEADERS,
|
|
34
|
-
responseType: "stream"
|
|
35
|
-
});
|
|
3
|
+
const isStream = req.body.stream === true;
|
|
36
4
|
|
|
37
|
-
|
|
5
|
+
const response = await axios({
|
|
6
|
+
method: "post",
|
|
7
|
+
url: TARGET_URL,
|
|
8
|
+
data: {
|
|
9
|
+
...req.body,
|
|
10
|
+
stream: isStream
|
|
11
|
+
},
|
|
12
|
+
headers: BASE_HEADERS,
|
|
13
|
+
responseType: isStream ? "stream" : "json"
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (isStream) {
|
|
38
17
|
res.setHeader("Content-Type", "text/event-stream");
|
|
39
18
|
res.setHeader("Cache-Control", "no-cache");
|
|
40
19
|
res.setHeader("Connection", "keep-alive");
|
|
41
20
|
|
|
42
|
-
|
|
43
|
-
response.data.on("data", (chunk) => {
|
|
44
|
-
res.write(chunk);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
response.data.on("end", () => {
|
|
48
|
-
res.end();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
response.data.on("error", (err) => {
|
|
52
|
-
console.error("❌ Stream Error:", err.message);
|
|
53
|
-
res.end();
|
|
54
|
-
});
|
|
55
|
-
|
|
21
|
+
response.data.pipe(res);
|
|
56
22
|
return;
|
|
57
23
|
}
|
|
58
24
|
|
|
59
|
-
// =========================
|
|
60
|
-
// 📦 非流式
|
|
61
|
-
// =========================
|
|
62
|
-
const response = await axios.post(
|
|
63
|
-
TARGET_URL,
|
|
64
|
-
{
|
|
65
|
-
...req.body,
|
|
66
|
-
stream: false
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
headers: BASE_HEADERS
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
25
|
res.json(response.data);
|
|
26
|
+
|
|
74
27
|
} catch (err) {
|
|
75
|
-
console.error("❌ Gateway Error:", err.
|
|
28
|
+
console.error("❌ Gateway Error:", err.message);
|
|
76
29
|
|
|
77
30
|
res.status(500).json({
|
|
78
31
|
error: err.response?.data || err.message
|
|
79
32
|
});
|
|
80
33
|
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
app.listen(3000, () => {
|
|
84
|
-
console.log("✅ AI Gateway running at http://localhost:3000");
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
name: Local Config
|
|
89
|
-
version: 1.0.0
|
|
90
|
-
schema: v1
|
|
91
|
-
|
|
92
|
-
models:
|
|
93
|
-
- name: qwen-chat
|
|
94
|
-
provider: openai
|
|
95
|
-
model: qwen15-32b
|
|
96
|
-
apiBase: http://localhost:3000/v1
|
|
97
|
-
apiKey: sk-dummy
|
|
98
|
-
roles:
|
|
99
|
-
- chat
|
|
100
|
-
|
|
101
|
-
- name: qwen-autocomplete
|
|
102
|
-
provider: openai
|
|
103
|
-
model: qwen15-32b
|
|
104
|
-
apiBase: http://localhost:3000/v1
|
|
105
|
-
apiKey: sk-dummy
|
|
106
|
-
roles:
|
|
107
|
-
- autocomplete
|
|
34
|
+
});
|