@blaxel/vercel 0.2.65-dev.77 → 0.2.65-preview.78
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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/model.js +45 -2
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/model.js +45 -2
- package/package.json +2 -2
package/dist/cjs/model.js
CHANGED
|
@@ -11,14 +11,57 @@ const openai_1 = require("@ai-sdk/openai");
|
|
|
11
11
|
const deepseek_1 = require("@ai-sdk/deepseek");
|
|
12
12
|
const core_1 = require("@blaxel/core");
|
|
13
13
|
const blModel = async (model, options) => {
|
|
14
|
-
const url = `${core_1.settings.runUrl}/${core_1.settings.workspace}/models/${model}`;
|
|
15
14
|
const modelData = await (0, core_1.getModelMetadata)(model);
|
|
16
15
|
if (!modelData) {
|
|
17
16
|
throw new Error(`Model ${model} not found`);
|
|
18
17
|
}
|
|
19
18
|
await (0, core_1.authenticate)();
|
|
20
|
-
const type = modelData?.spec.runtime?.type || "openai";
|
|
21
19
|
const modelId = modelData?.spec.runtime?.model || "gpt-4o";
|
|
20
|
+
// mk3 models use the direct gateway URL and always speak OpenAI-compatible API
|
|
21
|
+
if (modelData.spec.runtime?.generation === "mk3") {
|
|
22
|
+
const gatewayUrl = modelData.metadata.url;
|
|
23
|
+
if (!gatewayUrl) {
|
|
24
|
+
throw new Error(`Model ${model} is mk3 but has no gateway URL in metadata`);
|
|
25
|
+
}
|
|
26
|
+
const mk3Fetch = async (input, init) => {
|
|
27
|
+
await (0, core_1.authenticate)();
|
|
28
|
+
let existingHeaders = {};
|
|
29
|
+
if (init?.headers) {
|
|
30
|
+
if (init.headers instanceof Headers) {
|
|
31
|
+
init.headers.forEach((value, key) => {
|
|
32
|
+
existingHeaders[key] = value;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else if (Array.isArray(init.headers)) {
|
|
36
|
+
for (const [key, value] of init.headers) {
|
|
37
|
+
existingHeaders[key] = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
existingHeaders = { ...init.headers };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
delete existingHeaders['authorization'];
|
|
45
|
+
delete existingHeaders['Authorization'];
|
|
46
|
+
const headers = {
|
|
47
|
+
'Cache-Control': 'no-transform',
|
|
48
|
+
...existingHeaders,
|
|
49
|
+
...core_1.settings.headers,
|
|
50
|
+
};
|
|
51
|
+
return fetch(input, {
|
|
52
|
+
...init,
|
|
53
|
+
headers,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return (0, openai_1.createOpenAI)({
|
|
57
|
+
apiKey: "replaced",
|
|
58
|
+
baseURL: `${gatewayUrl}/v1`,
|
|
59
|
+
fetch: mk3Fetch,
|
|
60
|
+
...options,
|
|
61
|
+
})(model);
|
|
62
|
+
}
|
|
63
|
+
const url = `${core_1.settings.runUrl}/${core_1.settings.workspace}/models/${model}`;
|
|
64
|
+
const type = modelData?.spec.runtime?.type || "openai";
|
|
22
65
|
// Custom fetch function that refreshes authentication on each request
|
|
23
66
|
const authenticatedFetch = async (input, init) => {
|
|
24
67
|
await (0, core_1.authenticate)();
|