@qvac/sdk 0.1.1 โ 0.2.0
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/client/api/completion-stream.d.ts +19 -4
- package/dist/client/api/completion-stream.js +19 -4
- package/dist/client/api/delete-cache.d.ts +29 -0
- package/dist/client/api/delete-cache.js +47 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.js +1 -0
- package/dist/client/rpc/bare-client.d.ts +5 -0
- package/dist/client/rpc/bare-client.js +37 -1
- package/dist/examples/download-with-cancel.js +3 -3
- package/dist/examples/kv-cache-cleanup.d.ts +2 -0
- package/dist/examples/kv-cache-cleanup.js +88 -0
- package/dist/examples/kv-cache-custom-key.d.ts +2 -0
- package/dist/examples/kv-cache-custom-key.js +87 -0
- package/dist/examples/llamacpp-multimodal.js +3 -3
- package/dist/examples/rag/rag-hyperdb-workspaces.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models/hyperdrive/models.d.ts +49 -1
- package/dist/models/hyperdrive/models.js +105 -54
- package/dist/schemas/common.d.ts +22 -6
- package/dist/schemas/common.js +3 -0
- package/dist/schemas/completion-stream.d.ts +5 -3
- package/dist/schemas/completion-stream.js +3 -2
- package/dist/schemas/delete-cache.d.ts +17 -0
- package/dist/schemas/delete-cache.js +17 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.js +1 -0
- package/dist/schemas/llamacpp-config.d.ts +2 -1
- package/dist/schemas/llamacpp-config.js +5 -2
- package/dist/schemas/load-model.d.ts +16 -6
- package/dist/schemas/rag.d.ts +3 -0
- package/dist/schemas/rag.js +3 -1
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.js +135 -53
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.d.ts +13 -4
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +70 -7
- package/dist/server/bare/addons/load-model.js +1 -1
- package/dist/server/bare/registry/model-registry.d.ts +8 -1
- package/dist/server/bare/registry/model-registry.js +9 -0
- package/dist/server/rpc/handle-request.js +11 -0
- package/dist/server/rpc/handlers/completion-stream.js +31 -45
- package/dist/server/rpc/handlers/delete-cache.d.ts +3 -0
- package/dist/server/rpc/handlers/delete-cache.js +29 -0
- package/dist/server/rpc/handlers/index.d.ts +4 -0
- package/dist/server/rpc/handlers/index.js +4 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +0 -19
- package/dist/server/rpc/handlers/load-model/download-manager.js +10 -25
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +121 -80
- package/dist/server/rpc/handlers/load-model/resolve.js +8 -55
- package/package.json +6 -6
|
@@ -12,7 +12,6 @@ export const unregisterDownload = (key) => {
|
|
|
12
12
|
};
|
|
13
13
|
export const createHyperdriveDownloadKey = (hyperdriveKey, modelFileName) => `${hyperdriveKey}:${modelFileName}`;
|
|
14
14
|
export const createHttpDownloadKey = (url) => `http:${url}`;
|
|
15
|
-
export const getAllActiveDownloads = () => new Map(activeDownloads);
|
|
16
15
|
export const setClearCacheFlag = (downloadKey, clearCache) => {
|
|
17
16
|
if (clearCache) {
|
|
18
17
|
clearCacheFlags.set(downloadKey, true);
|
|
@@ -39,24 +38,6 @@ export const cancelAllDownloads = () => {
|
|
|
39
38
|
console.log(`๐งน Cancelling ${activeDownloads.size} active downloads`);
|
|
40
39
|
Array.from(activeDownloads.keys()).forEach((key) => createCancelFunction(key)());
|
|
41
40
|
};
|
|
42
|
-
export const getDownloadStats = () => ({
|
|
43
|
-
activeCount: activeDownloads.size,
|
|
44
|
-
downloads: Array.from(activeDownloads.entries()).map(([key, entry]) => ({
|
|
45
|
-
key,
|
|
46
|
-
startTime: entry.startTime,
|
|
47
|
-
duration: Date.now() - entry.startTime,
|
|
48
|
-
type: entry.type,
|
|
49
|
-
...(entry.type === "hyperdrive"
|
|
50
|
-
? {
|
|
51
|
-
hyperdriveKey: entry.hyperdriveKey,
|
|
52
|
-
modelFileName: entry.modelFileName,
|
|
53
|
-
}
|
|
54
|
-
: {
|
|
55
|
-
url: entry.url,
|
|
56
|
-
modelPath: entry.modelPath,
|
|
57
|
-
}),
|
|
58
|
-
})),
|
|
59
|
-
});
|
|
60
41
|
// Register cleanup handlers for graceful shutdown
|
|
61
42
|
let cleanupRegistered = false;
|
|
62
43
|
let isCleaningUp = false;
|
|
@@ -79,10 +60,14 @@ const registerCleanupHandlers = () => {
|
|
|
79
60
|
console.error("โ Error during download cleanup:", error);
|
|
80
61
|
}
|
|
81
62
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
let handlingExit = false;
|
|
64
|
+
const exitHandler = async () => {
|
|
65
|
+
if (handlingExit)
|
|
66
|
+
return;
|
|
67
|
+
handlingExit = true;
|
|
68
|
+
await cleanup();
|
|
69
|
+
process.exit(0);
|
|
70
|
+
};
|
|
71
|
+
process.once("SIGTERM", () => void exitHandler());
|
|
72
|
+
process.once("SIGINT", () => void exitHandler());
|
|
88
73
|
};
|
|
@@ -10,24 +10,49 @@ import { getEnv } from "../../../worker.js";
|
|
|
10
10
|
import { getModelsCacheDir, generateShortHash } from "../../../utils/index.js";
|
|
11
11
|
import { getModelBySrc } from "../../../../models/hyperdrive/index.js";
|
|
12
12
|
import { getActiveDownload, registerDownload, unregisterDownload, createHyperdriveDownloadKey, shouldClearCache, clearClearCacheFlag, } from "./download-manager.js";
|
|
13
|
+
function createProgressHandler(blob, progressCallback, downloadKey, initialBytes = 0) {
|
|
14
|
+
let downloadedBytes = initialBytes;
|
|
15
|
+
return (index, bytes) => {
|
|
16
|
+
if (index >= blob.blockOffset &&
|
|
17
|
+
index < blob.blockOffset + blob.blockLength) {
|
|
18
|
+
downloadedBytes += bytes;
|
|
19
|
+
if (progressCallback && downloadKey) {
|
|
20
|
+
progressCallback({
|
|
21
|
+
type: "modelProgress",
|
|
22
|
+
downloaded: downloadedBytes,
|
|
23
|
+
total: blob.byteLength,
|
|
24
|
+
percentage: blob.byteLength > 0 ? (downloadedBytes / blob.byteLength) * 100 : 0,
|
|
25
|
+
downloadKey,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
13
31
|
async function setupHyperdrive(hyperdriveKey, corestoreDir) {
|
|
14
32
|
const corestore = new Corestore(corestoreDir);
|
|
15
33
|
await corestore.ready();
|
|
16
34
|
const drive = new Hyperdrive(corestore, Buffer.from(hyperdriveKey, "hex"));
|
|
17
35
|
await drive.ready();
|
|
18
36
|
const swarm = new Hyperswarm();
|
|
19
|
-
|
|
37
|
+
const doneFindingPeers = drive.findingPeers();
|
|
20
38
|
swarm.on("connection", (connection) => {
|
|
21
39
|
console.log(`๐ค Connected to peer for hyperdrive download`);
|
|
22
40
|
drive.replicate(connection);
|
|
23
41
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
doneFindingPeers();
|
|
42
|
+
swarm.join(drive.discoveryKey, { server: false, client: true });
|
|
43
|
+
swarm.flush().then(doneFindingPeers, doneFindingPeers);
|
|
27
44
|
return { corestore, drive, swarm, corestoreDir };
|
|
28
45
|
}
|
|
29
46
|
async function cleanupHyperdrive(setup) {
|
|
30
47
|
console.log("๐งน Cleaning up hyperdrive setup");
|
|
48
|
+
if (!setup.swarm.suspended) {
|
|
49
|
+
try {
|
|
50
|
+
await setup.swarm.suspend();
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// If suspend fails, continue with cleanup
|
|
54
|
+
}
|
|
55
|
+
}
|
|
31
56
|
await setup.swarm.destroy();
|
|
32
57
|
await setup.drive.close();
|
|
33
58
|
await setup.corestore.close();
|
|
@@ -42,43 +67,81 @@ export async function deleteCorestoreDirectory(corestoreDir) {
|
|
|
42
67
|
}
|
|
43
68
|
}
|
|
44
69
|
async function findFileInHyperdrive(drive, modelFileName) {
|
|
70
|
+
if (drive.core.length === 0) {
|
|
71
|
+
// this method will update the length of the core using the first peer it finds
|
|
72
|
+
// this will ensure that the hyperdrive is usable
|
|
73
|
+
await drive.core.update();
|
|
74
|
+
}
|
|
45
75
|
const paths = [modelFileName, `/${modelFileName}`, `./${modelFileName}`];
|
|
46
|
-
let entry = null;
|
|
47
|
-
let targetPath = modelFileName;
|
|
48
76
|
for (const pathVariation of paths) {
|
|
49
77
|
try {
|
|
50
|
-
entry = await drive.entry(pathVariation);
|
|
78
|
+
const entry = await drive.entry(pathVariation, { wait: true });
|
|
51
79
|
if (entry) {
|
|
52
|
-
targetPath
|
|
53
|
-
break;
|
|
80
|
+
return { entry, targetPath: pathVariation };
|
|
54
81
|
}
|
|
55
82
|
}
|
|
56
83
|
catch {
|
|
57
84
|
// Continue trying other paths
|
|
58
85
|
}
|
|
59
86
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
87
|
+
// If not found, list available files for debugging
|
|
88
|
+
const availableFiles = [];
|
|
89
|
+
try {
|
|
90
|
+
// Try both with and without leading slash
|
|
91
|
+
for (const prefix of ["/", ""]) {
|
|
92
|
+
const files = drive.list(prefix, { recursive: true, wait: true });
|
|
93
|
+
for await (const file of files) {
|
|
66
94
|
availableFiles.push(file.key);
|
|
67
95
|
}
|
|
68
|
-
if (availableFiles.length
|
|
69
|
-
|
|
70
|
-
const noSlashFiles = drive.list("", false);
|
|
71
|
-
for await (const file of noSlashFiles) {
|
|
72
|
-
availableFiles.push(file.key);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
throw new Error(`File ${modelFileName} not found in hyperdrive. Available files: ${availableFiles.join(", ")}`);
|
|
96
|
+
if (availableFiles.length > 0)
|
|
97
|
+
break;
|
|
76
98
|
}
|
|
77
|
-
|
|
78
|
-
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// Ignore listing errors
|
|
102
|
+
}
|
|
103
|
+
const filesInfo = availableFiles.length > 0
|
|
104
|
+
? `Available files: ${availableFiles.join(", ")}`
|
|
105
|
+
: "Could not list available files";
|
|
106
|
+
throw new Error(`File ${modelFileName} not found in hyperdrive. ${filesInfo}`);
|
|
107
|
+
}
|
|
108
|
+
async function checkFileDownloaded(drive, entry) {
|
|
109
|
+
const blobs = await drive.getBlobs();
|
|
110
|
+
const blob = entry?.value?.blob;
|
|
111
|
+
if (!blob) {
|
|
112
|
+
return {
|
|
113
|
+
blobs,
|
|
114
|
+
blocksDownloaded: 0,
|
|
115
|
+
totalBlocks: 0,
|
|
116
|
+
totalBytes: 0,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// Check how many blocks are already downloaded
|
|
120
|
+
let blocksDownloaded = 0;
|
|
121
|
+
for (let i = blob.blockOffset; i < blob.blockOffset + blob.blockLength; i++) {
|
|
122
|
+
const hasBlock = await blobs.core.has(i);
|
|
123
|
+
if (hasBlock) {
|
|
124
|
+
blocksDownloaded++;
|
|
79
125
|
}
|
|
80
126
|
}
|
|
81
|
-
return {
|
|
127
|
+
return {
|
|
128
|
+
blobs,
|
|
129
|
+
blocksDownloaded,
|
|
130
|
+
totalBlocks: blob.blockLength,
|
|
131
|
+
totalBytes: blob.byteLength,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
async function validateFileExistence(drive, file) {
|
|
135
|
+
const { entry, targetPath } = await findFileInHyperdrive(drive, file);
|
|
136
|
+
const { blobs, blocksDownloaded, totalBlocks, totalBytes } = await checkFileDownloaded(drive, entry);
|
|
137
|
+
return {
|
|
138
|
+
entry,
|
|
139
|
+
blobs,
|
|
140
|
+
targetPath,
|
|
141
|
+
blocksDownloaded,
|
|
142
|
+
totalBlocks,
|
|
143
|
+
totalBytes,
|
|
144
|
+
};
|
|
82
145
|
}
|
|
83
146
|
async function validateFileChecksum(filePath, expectedChecksum) {
|
|
84
147
|
console.log(`๐ Validating SHA256 checksum...`);
|
|
@@ -153,13 +216,15 @@ async function performHyperdriveDownload(modelPath, modelFileName, hyperdriveKey
|
|
|
153
216
|
}
|
|
154
217
|
console.log(`Downloading model from hyperdrive ${hyperdriveKey} to ${modelPath}`);
|
|
155
218
|
const setup = await setupHyperdrive(hyperdriveKey, corestoreDir);
|
|
156
|
-
let downloadedBytes = 0;
|
|
157
|
-
let totalBytes = 0;
|
|
158
219
|
// Set up abort handler
|
|
159
220
|
let readStream;
|
|
160
221
|
let writeStream;
|
|
161
222
|
const cleanup = () => {
|
|
162
223
|
console.log("๐ Aborting hyperdrive download...");
|
|
224
|
+
setup.swarm.suspended = true;
|
|
225
|
+
setup.swarm.suspend().catch(() => {
|
|
226
|
+
// Ignore errors during emergency suspend
|
|
227
|
+
});
|
|
163
228
|
// Destroy streams if they exist
|
|
164
229
|
if (readStream) {
|
|
165
230
|
readStream.destroy();
|
|
@@ -169,48 +234,19 @@ async function performHyperdriveDownload(modelPath, modelFileName, hyperdriveKey
|
|
|
169
234
|
}
|
|
170
235
|
};
|
|
171
236
|
signal?.addEventListener("abort", cleanup);
|
|
237
|
+
let downloadHandler;
|
|
172
238
|
try {
|
|
173
|
-
const
|
|
174
|
-
const { entry, targetPath } = result;
|
|
175
|
-
totalBytes = entry?.value?.blob?.byteLength || 0;
|
|
176
|
-
console.log(`๐ Model size: ${totalBytes} bytes (${(totalBytes / 1024 / 1024).toFixed(2)} MB)`);
|
|
177
|
-
// Get blobs and file blob range
|
|
178
|
-
const blobs = await setup.drive.getBlobs();
|
|
239
|
+
const { entry, blobs, targetPath, blocksDownloaded, totalBlocks, totalBytes, } = await validateFileExistence(setup.drive, modelFileName);
|
|
179
240
|
const blob = entry?.value?.blob;
|
|
180
241
|
if (!blob) {
|
|
181
242
|
throw new Error(`No blob found for ${modelFileName}`);
|
|
182
243
|
}
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const hasBlock = await blobs.core.has(i);
|
|
187
|
-
if (hasBlock) {
|
|
188
|
-
alreadyDownloaded++;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
downloadedBytes = 0;
|
|
192
|
-
if (alreadyDownloaded > 0) {
|
|
193
|
-
console.log(`๐ฅ Resuming download (${alreadyDownloaded}/${blob.blockLength} blocks already in corestore)`);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
console.log(`๐ฅ Starting fresh download`);
|
|
197
|
-
}
|
|
244
|
+
// Calculate already downloaded bytes for resuming
|
|
245
|
+
const bytesPerBlock = totalBlocks > 0 ? totalBytes / totalBlocks : 0;
|
|
246
|
+
const initialBytes = Math.floor(blocksDownloaded * bytesPerBlock);
|
|
198
247
|
// Track only downloads for blocks within our file's blob range
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
index < blob.blockOffset + blob.blockLength) {
|
|
202
|
-
downloadedBytes += bytes;
|
|
203
|
-
if (progressCallback) {
|
|
204
|
-
progressCallback({
|
|
205
|
-
type: "modelProgress",
|
|
206
|
-
downloaded: downloadedBytes,
|
|
207
|
-
total: totalBytes,
|
|
208
|
-
percentage: totalBytes > 0 ? (downloadedBytes / totalBytes) * 100 : 0,
|
|
209
|
-
downloadKey,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
248
|
+
downloadHandler = createProgressHandler(blob, progressCallback, downloadKey, initialBytes);
|
|
249
|
+
blobs.core.on("download", downloadHandler);
|
|
214
250
|
// Check if aborted before starting streams
|
|
215
251
|
if (signal?.aborted) {
|
|
216
252
|
throw new Error("Download cancelled");
|
|
@@ -223,15 +259,13 @@ async function performHyperdriveDownload(modelPath, modelFileName, hyperdriveKey
|
|
|
223
259
|
readStream.pipe(writeStream);
|
|
224
260
|
// Wait for download to complete
|
|
225
261
|
await new Promise((resolve, reject) => {
|
|
226
|
-
writeStream.on("finish",
|
|
262
|
+
writeStream.on("finish", resolve);
|
|
227
263
|
writeStream.on("error", reject);
|
|
228
264
|
readStream.on("error", reject);
|
|
229
265
|
// Also reject on abort
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}, { once: true });
|
|
234
|
-
}
|
|
266
|
+
signal?.addEventListener("abort", () => {
|
|
267
|
+
reject(new Error("Download cancelled"));
|
|
268
|
+
}, { once: true });
|
|
235
269
|
});
|
|
236
270
|
console.log(`โ
Model downloaded successfully to ${modelPath}`);
|
|
237
271
|
// Delete corestore directory after successful download (only when not seeding, to save space)
|
|
@@ -249,22 +283,29 @@ async function performHyperdriveDownload(modelPath, modelFileName, hyperdriveKey
|
|
|
249
283
|
}
|
|
250
284
|
finally {
|
|
251
285
|
signal?.removeEventListener("abort", cleanup);
|
|
286
|
+
if (downloadHandler) {
|
|
287
|
+
try {
|
|
288
|
+
const { blobs } = await validateFileExistence(setup.drive, modelFileName);
|
|
289
|
+
blobs.core.off("download", downloadHandler);
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
// If we can't get blobs, setup is already closed
|
|
293
|
+
}
|
|
294
|
+
}
|
|
252
295
|
if (!seed) {
|
|
253
296
|
await cleanupHyperdrive(setup);
|
|
254
297
|
}
|
|
255
298
|
// Only delete corestore and partial file if user explicitly requested clearCache
|
|
256
|
-
if (signal?.aborted) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// no-op
|
|
263
|
-
}
|
|
264
|
-
await deleteCorestoreDirectory(corestoreDir);
|
|
299
|
+
if (signal?.aborted && shouldClearCache(downloadKey)) {
|
|
300
|
+
try {
|
|
301
|
+
await fsPromises.unlink(modelPath);
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
// no-op
|
|
265
305
|
}
|
|
266
|
-
|
|
306
|
+
await deleteCorestoreDirectory(corestoreDir);
|
|
267
307
|
}
|
|
308
|
+
clearClearCacheFlag(downloadKey);
|
|
268
309
|
}
|
|
269
310
|
}
|
|
270
311
|
export async function downloadModelFromHyperdrive(hyperdriveKey, modelFileName, seed, progressCallback, expectedChecksum) {
|
|
@@ -1,46 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { models } from "../../../../models/hyperdrive/models.js";
|
|
2
2
|
import { hyperdriveUrlSchema } from "../../../../schemas/index.js";
|
|
3
3
|
import { getModelsCacheDir } from "../../../utils/index.js";
|
|
4
4
|
import { promises as fsPromises } from "bare-fs";
|
|
5
5
|
import path from "bare-path";
|
|
6
6
|
import { downloadModelFromHttp } from "./http.js";
|
|
7
7
|
import { downloadModelFromHyperdrive } from "./hyperdrive.js";
|
|
8
|
-
/**
|
|
9
|
-
* Attempts to resolve a model from cache (without validation)
|
|
10
|
-
* Validation will be handled by the hyperdrive download logic
|
|
11
|
-
*/
|
|
12
|
-
async function tryResolveCachedModel(modelId) {
|
|
13
|
-
const cacheDir = getModelsCacheDir();
|
|
14
|
-
const cachedPath = path.join(cacheDir, modelId);
|
|
15
|
-
try {
|
|
16
|
-
await fsPromises.access(cachedPath);
|
|
17
|
-
// File exists - return null to let hyperdrive validation handle size/checksum
|
|
18
|
-
// This ensures partial downloads are properly resumed instead of being
|
|
19
|
-
// incorrectly validated and deleted
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
// File doesn't exist
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Resolves a known model by ID from hyperdrive, checking cache first
|
|
29
|
-
*/
|
|
30
|
-
async function resolveKnownModel(model, modelIdOrPath, progressCallback, seed) {
|
|
31
|
-
if (!model) {
|
|
32
|
-
throw new Error("Model is null");
|
|
33
|
-
}
|
|
34
|
-
console.log(`Loading model ID '${modelIdOrPath}' from hyperdrive`);
|
|
35
|
-
// Try to resolve from cache first
|
|
36
|
-
const cachedPath = await tryResolveCachedModel(model.modelId);
|
|
37
|
-
if (cachedPath) {
|
|
38
|
-
return cachedPath;
|
|
39
|
-
}
|
|
40
|
-
// Not cached or invalid, download from hyperdrive
|
|
41
|
-
const downloadedPath = await downloadModelFromHyperdrive(model.hyperdriveKey, model.modelId, seed, progressCallback, model.sha256Checksum);
|
|
42
|
-
return downloadedPath;
|
|
43
|
-
}
|
|
44
8
|
/**
|
|
45
9
|
* Resolves a local file path or cached file
|
|
46
10
|
*/
|
|
@@ -84,10 +48,7 @@ export async function resolveModelPath(modelSrc, progressCallback, seed) {
|
|
|
84
48
|
let actualPath;
|
|
85
49
|
// Validate seeding is only used with hyperdrive models
|
|
86
50
|
if (seed && !hyperdriveKey) {
|
|
87
|
-
|
|
88
|
-
if (!model) {
|
|
89
|
-
throw new Error("Seeding is only supported for hyperdrive models");
|
|
90
|
-
}
|
|
51
|
+
throw new Error("Seeding is only supported for hyperdrive models");
|
|
91
52
|
}
|
|
92
53
|
// Check if it's an HTTP/HTTPS URL
|
|
93
54
|
if (actualModelSrc.startsWith("http://") ||
|
|
@@ -101,21 +62,13 @@ export async function resolveModelPath(modelSrc, progressCallback, seed) {
|
|
|
101
62
|
console.log(`Loading from hyperdrive: ${hyperdriveKey}`);
|
|
102
63
|
actualPath = await downloadModelFromHyperdrive(hyperdriveKey, actualModelSrc, seed, progressCallback);
|
|
103
64
|
}
|
|
65
|
+
else if (actualModelSrc.includes("/") || actualModelSrc.includes("\\")) {
|
|
66
|
+
// Handle file paths (absolute or relative with slashes)
|
|
67
|
+
actualPath = actualModelSrc;
|
|
68
|
+
}
|
|
104
69
|
else {
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
if (model) {
|
|
108
|
-
actualPath = await resolveKnownModel(model, actualModelSrc, progressCallback, seed);
|
|
109
|
-
}
|
|
110
|
-
else if (actualModelSrc.includes("/") || actualModelSrc.includes("\\")) {
|
|
111
|
-
// Handle file paths (absolute or relative with slashes)
|
|
112
|
-
console.log(`Loading from file: ${actualModelSrc}`);
|
|
113
|
-
actualPath = actualModelSrc;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
// Handle local files and cached files
|
|
117
|
-
actualPath = await resolveLocalOrCachedFile(actualModelSrc);
|
|
118
|
-
}
|
|
70
|
+
// Handle local files and cached files
|
|
71
|
+
actualPath = await resolveLocalOrCachedFile(actualModelSrc);
|
|
119
72
|
}
|
|
120
73
|
return actualPath;
|
|
121
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qvac/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"bare:ensureprebuilds:whispercpp": "cp -r node_modules/@qvac/transcription-whispercpp/prebuilds/android-arm64 node_modules/@qvac/transcription-whispercpp/prebuilds/android-ia32 && cp -r node_modules/@qvac/transcription-whispercpp/prebuilds/android-arm64 node_modules/@qvac/transcription-whispercpp/prebuilds/android-arm && cp -r node_modules/@qvac/transcription-whispercpp/prebuilds/android-arm64 node_modules/@qvac/transcription-whispercpp/prebuilds/android-x64",
|
|
46
46
|
"bare:ensureprebuilds:embeddings": "cp -r node_modules/@qvac/embed-llamacpp/prebuilds/android-arm64 node_modules/@qvac/embed-llamacpp/prebuilds/android-ia32 && cp -r node_modules/@qvac/embed-llamacpp/prebuilds/android-arm64 node_modules/@qvac/embed-llamacpp/prebuilds/android-arm && cp -r node_modules/@qvac/embed-llamacpp/prebuilds/android-arm64 node_modules/@qvac/embed-llamacpp/prebuilds/android-x64",
|
|
47
47
|
"bare:ensureprebuilds": "bun run bare:ensureprebuilds:llamacpp && bun run bare:ensureprebuilds:whispercpp && bun run bare:ensureprebuilds:embeddings",
|
|
48
|
-
"prepare": "bun run husky",
|
|
48
|
+
"prepare:husky": "bun run husky",
|
|
49
49
|
"bare:example": "./scripts/run-with-bare.sh",
|
|
50
50
|
"docs_api:website": "typedoc --out ./docs/api/website --entryPoints index.ts --entryPointStrategy expand --readme none",
|
|
51
51
|
"docs_api:markdown": "typedoc --plugin typedoc-plugin-markdown --out ./docs/api/markdown --entryPoints index.ts --entryPointStrategy expand --readme none && sed -i '1,4d' ./docs/api/markdown/README.md",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"update-models": "node ./scripts/update-models.js"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@qvac/embed-llamacpp": "^0.1
|
|
57
|
-
"@qvac/llm-llamacpp": "^0.
|
|
56
|
+
"@qvac/embed-llamacpp": "^0.3.1",
|
|
57
|
+
"@qvac/llm-llamacpp": "^0.3.2",
|
|
58
58
|
"@qvac/decoder-audio": "^0.1.0",
|
|
59
59
|
"@qvac/error": "^0.1.0",
|
|
60
60
|
"@qvac/langdetect-text": "^0.1.0",
|
|
61
61
|
"@qvac/logging": "^0.1.0",
|
|
62
|
-
"@qvac/rag": "^0.1
|
|
62
|
+
"@qvac/rag": "^0.2.1",
|
|
63
63
|
"@qvac/transcription-whispercpp": "^0.1.4",
|
|
64
64
|
"@qvac/translation-nmtcpp": "^0.1.0",
|
|
65
65
|
"fast-safe-stringify": "2.1.1",
|
|
@@ -126,4 +126,4 @@
|
|
|
126
126
|
"patchedDependencies": {
|
|
127
127
|
"bare-rpc@0.2.11": "patches/bare-rpc@0.2.11.patch"
|
|
128
128
|
}
|
|
129
|
-
}
|
|
129
|
+
}
|