mslxdff 0.1.26 → 0.1.28
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/bin/mslxdff.js +6 -0
- package/package.json +1 -1
- package/src/auto.js +26 -11
- package/src/routes.js +618 -529
- package/src/upstream.js +25 -4
package/src/upstream.js
CHANGED
|
@@ -4,10 +4,10 @@ export function createUpstreamClient({
|
|
|
4
4
|
connectTimeoutMs = Number(process.env.UPSTREAM_CONNECT_TIMEOUT_MS) || 30_000,
|
|
5
5
|
retry = {
|
|
6
6
|
network: { attempts: 2, delayMs: 1000 },
|
|
7
|
-
429: { attempts:
|
|
8
|
-
502: { attempts:
|
|
9
|
-
503: { attempts:
|
|
10
|
-
504: { attempts:
|
|
7
|
+
429: { attempts: 1, delayMs: 500 },
|
|
8
|
+
502: { attempts: 1, delayMs: 500 },
|
|
9
|
+
503: { attempts: 1, delayMs: 500 },
|
|
10
|
+
504: { attempts: 1, delayMs: 500 },
|
|
11
11
|
},
|
|
12
12
|
fetchImpl = fetch,
|
|
13
13
|
} = {}) {
|
|
@@ -20,21 +20,42 @@ export function createUpstreamClient({
|
|
|
20
20
|
|
|
21
21
|
async function chat(body) {
|
|
22
22
|
const url = `${baseUrl}/zen/v1/chat/completions`;
|
|
23
|
+
const t0 = performance.now();
|
|
24
|
+
const attempts = [];
|
|
25
|
+
let waitMs = 0;
|
|
23
26
|
for (let attempt = 0; ; attempt++) {
|
|
27
|
+
const t = performance.now();
|
|
24
28
|
const result = await attemptOnce(url, body);
|
|
29
|
+
attempts.push({
|
|
30
|
+
attempt,
|
|
31
|
+
type: result instanceof Error ? "network" : `http${result.status}`,
|
|
32
|
+
ms: Math.round(performance.now() - t),
|
|
33
|
+
});
|
|
25
34
|
if (result instanceof Error) {
|
|
26
35
|
const entry = retry?.network;
|
|
27
36
|
if (entry && attempt < entry.attempts) {
|
|
28
37
|
await sleep(entry.delayMs);
|
|
38
|
+
waitMs += entry.delayMs;
|
|
29
39
|
continue;
|
|
30
40
|
}
|
|
41
|
+
result._t = {
|
|
42
|
+
attempts,
|
|
43
|
+
waitMs,
|
|
44
|
+
totalMs: Math.round(performance.now() - t0),
|
|
45
|
+
};
|
|
31
46
|
throw result;
|
|
32
47
|
}
|
|
33
48
|
const entry = retry?.[result.status];
|
|
34
49
|
if (entry && attempt < entry.attempts) {
|
|
35
50
|
await sleep(entry.delayMs);
|
|
51
|
+
waitMs += entry.delayMs;
|
|
36
52
|
continue;
|
|
37
53
|
}
|
|
54
|
+
result._t = {
|
|
55
|
+
attempts,
|
|
56
|
+
waitMs,
|
|
57
|
+
totalMs: Math.round(performance.now() - t0),
|
|
58
|
+
};
|
|
38
59
|
return result;
|
|
39
60
|
}
|
|
40
61
|
}
|