@qvac/sdk 0.1.0-dev.1760648187.328e967
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/LICENSE +202 -0
- package/README.md +301 -0
- package/dist/client/api/cancel.d.ts +25 -0
- package/dist/client/api/cancel.js +37 -0
- package/dist/client/api/completion-stream.d.ts +50 -0
- package/dist/client/api/completion-stream.js +103 -0
- package/dist/client/api/download-asset.d.ts +39 -0
- package/dist/client/api/download-asset.js +72 -0
- package/dist/client/api/embed.d.ts +11 -0
- package/dist/client/api/embed.js +24 -0
- package/dist/client/api/index.d.ts +13 -0
- package/dist/client/api/index.js +12 -0
- package/dist/client/api/load-model.d.ts +98 -0
- package/dist/client/api/load-model.js +154 -0
- package/dist/client/api/logging-stream.d.ts +21 -0
- package/dist/client/api/logging-stream.js +32 -0
- package/dist/client/api/ping.d.ts +11 -0
- package/dist/client/api/ping.js +18 -0
- package/dist/client/api/provide.d.ts +18 -0
- package/dist/client/api/provide.js +27 -0
- package/dist/client/api/rag.d.ts +42 -0
- package/dist/client/api/rag.js +97 -0
- package/dist/client/api/transcribe.d.ts +24 -0
- package/dist/client/api/transcribe.js +52 -0
- package/dist/client/api/translate.d.ts +47 -0
- package/dist/client/api/translate.js +114 -0
- package/dist/client/api/unload-model.d.ts +11 -0
- package/dist/client/api/unload-model.js +26 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +1 -0
- package/dist/client/logging-stream-registry.d.ts +5 -0
- package/dist/client/logging-stream-registry.js +60 -0
- package/dist/client/rpc/bare-client.d.ts +112 -0
- package/dist/client/rpc/bare-client.js +82 -0
- package/dist/client/rpc/bare-rpc-client.d.ts +4 -0
- package/dist/client/rpc/bare-rpc-client.js +87 -0
- package/dist/client/rpc/expo-rpc-client.d.ts +3 -0
- package/dist/client/rpc/expo-rpc-client.js +57 -0
- package/dist/client/rpc/node-rpc-client.d.ts +9 -0
- package/dist/client/rpc/node-rpc-client.js +99 -0
- package/dist/client/rpc/rpc-client.d.ts +5 -0
- package/dist/client/rpc/rpc-client.js +91 -0
- package/dist/client/rpc/rpc-error.d.ts +19 -0
- package/dist/client/rpc/rpc-error.js +39 -0
- package/dist/constants/audio.d.ts +3 -0
- package/dist/constants/audio.js +17 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +1 -0
- package/dist/examples/delegated-inference/consumer.d.ts +2 -0
- package/dist/examples/delegated-inference/consumer.js +56 -0
- package/dist/examples/delegated-inference/provider.d.ts +2 -0
- package/dist/examples/delegated-inference/provider.js +57 -0
- package/dist/examples/download-with-cancel.d.ts +2 -0
- package/dist/examples/download-with-cancel.js +46 -0
- package/dist/examples/embed-hyperdrive.d.ts +2 -0
- package/dist/examples/embed-hyperdrive.js +19 -0
- package/dist/examples/kv-cache-example.d.ts +2 -0
- package/dist/examples/kv-cache-example.js +74 -0
- package/dist/examples/llamacpp-file-logging.d.ts +2 -0
- package/dist/examples/llamacpp-file-logging.js +62 -0
- package/dist/examples/llamacpp-filesystem.d.ts +2 -0
- package/dist/examples/llamacpp-filesystem.js +40 -0
- package/dist/examples/llamacpp-http.d.ts +2 -0
- package/dist/examples/llamacpp-http.js +41 -0
- package/dist/examples/llamacpp-hyperdrive.d.ts +2 -0
- package/dist/examples/llamacpp-hyperdrive.js +39 -0
- package/dist/examples/llamacpp-multimodal.d.ts +2 -0
- package/dist/examples/llamacpp-multimodal.js +62 -0
- package/dist/examples/llamacpp-native-tools.d.ts +2 -0
- package/dist/examples/llamacpp-native-tools.js +64 -0
- package/dist/examples/llamacpp-tools-routing.d.ts +2 -0
- package/dist/examples/llamacpp-tools-routing.js +364 -0
- package/dist/examples/llamacpp-tools.d.ts +2 -0
- package/dist/examples/llamacpp-tools.js +81 -0
- package/dist/examples/multi-model-demo.d.ts +2 -0
- package/dist/examples/multi-model-demo.js +75 -0
- package/dist/examples/parallel-download.d.ts +2 -0
- package/dist/examples/parallel-download.js +21 -0
- package/dist/examples/rag/rag-chromadb.d.ts +2 -0
- package/dist/examples/rag/rag-chromadb.js +130 -0
- package/dist/examples/rag/rag-hyperdb-workspaces.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb-workspaces.js +106 -0
- package/dist/examples/rag/rag-hyperdb.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb.js +50 -0
- package/dist/examples/rag/rag-lancedb.d.ts +2 -0
- package/dist/examples/rag/rag-lancedb.js +95 -0
- package/dist/examples/rag/rag-sqlite.d.ts +2 -0
- package/dist/examples/rag/rag-sqlite.js +107 -0
- package/dist/examples/seed-hyperdrive.d.ts +2 -0
- package/dist/examples/seed-hyperdrive.js +21 -0
- package/dist/examples/translation/translation-indic.d.ts +2 -0
- package/dist/examples/translation/translation-indic.js +30 -0
- package/dist/examples/translation/translation-llm-context.d.ts +2 -0
- package/dist/examples/translation/translation-llm-context.js +30 -0
- package/dist/examples/translation/translation-llm.d.ts +2 -0
- package/dist/examples/translation/translation-llm.js +38 -0
- package/dist/examples/translation/translation-opus.d.ts +2 -0
- package/dist/examples/translation/translation-opus.js +30 -0
- package/dist/examples/translation/translation-stream.d.ts +2 -0
- package/dist/examples/translation/translation-stream.js +35 -0
- package/dist/examples/whispercpp-filesystem.d.ts +2 -0
- package/dist/examples/whispercpp-filesystem.js +43 -0
- package/dist/examples/whispercpp-microphone-record.d.ts +2 -0
- package/dist/examples/whispercpp-microphone-record.js +311 -0
- package/dist/expo/plugins/index.d.ts +5 -0
- package/dist/expo/plugins/index.js +5 -0
- package/dist/expo/plugins/withMobileBundle.d.ts +8 -0
- package/dist/expo/plugins/withMobileBundle.js +60 -0
- package/dist/expo/plugins/withOpenCL.d.ts +9 -0
- package/dist/expo/plugins/withOpenCL.js +118 -0
- package/dist/expo/plugins/withQvacSDK.d.ts +9 -0
- package/dist/expo/plugins/withQvacSDK.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/logging/base-logger.d.ts +7 -0
- package/dist/logging/base-logger.js +55 -0
- package/dist/logging/index.d.ts +4 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/logger.d.ts +5 -0
- package/dist/logging/logger.js +28 -0
- package/dist/logging/stream-logger.d.ts +3 -0
- package/dist/logging/stream-logger.js +9 -0
- package/dist/logging/transport.d.ts +3 -0
- package/dist/logging/transport.js +15 -0
- package/dist/logging/types.d.ts +18 -0
- package/dist/logging/types.js +1 -0
- package/dist/logging/utils.d.ts +4 -0
- package/dist/logging/utils.js +47 -0
- package/dist/models/hyperdrive/index.d.ts +2 -0
- package/dist/models/hyperdrive/index.js +2 -0
- package/dist/models/hyperdrive/models.d.ts +475 -0
- package/dist/models/hyperdrive/models.js +534 -0
- package/dist/schemas/cancel.d.ts +33 -0
- package/dist/schemas/cancel.js +25 -0
- package/dist/schemas/common.d.ts +626 -0
- package/dist/schemas/common.js +47 -0
- package/dist/schemas/completion-stream.d.ts +125 -0
- package/dist/schemas/completion-stream.js +53 -0
- package/dist/schemas/delegate.d.ts +9 -0
- package/dist/schemas/delegate.js +9 -0
- package/dist/schemas/download-asset.d.ts +75 -0
- package/dist/schemas/download-asset.js +43 -0
- package/dist/schemas/embed.d.ts +20 -0
- package/dist/schemas/embed.js +14 -0
- package/dist/schemas/error.d.ts +13 -0
- package/dist/schemas/error.js +35 -0
- package/dist/schemas/index.d.ts +19 -0
- package/dist/schemas/index.js +19 -0
- package/dist/schemas/llamacpp-config.d.ts +30 -0
- package/dist/schemas/llamacpp-config.js +39 -0
- package/dist/schemas/load-model.d.ts +1259 -0
- package/dist/schemas/load-model.js +108 -0
- package/dist/schemas/logging-stream.d.ts +27 -0
- package/dist/schemas/logging-stream.js +16 -0
- package/dist/schemas/ping.d.ts +11 -0
- package/dist/schemas/ping.js +8 -0
- package/dist/schemas/provide.d.ts +43 -0
- package/dist/schemas/provide.js +25 -0
- package/dist/schemas/rag.d.ts +159 -0
- package/dist/schemas/rag.js +78 -0
- package/dist/schemas/transcription.d.ts +24 -0
- package/dist/schemas/transcription.js +15 -0
- package/dist/schemas/translate.d.ts +82 -0
- package/dist/schemas/translate.js +42 -0
- package/dist/schemas/translation-config.d.ts +83 -0
- package/dist/schemas/translation-config.js +46 -0
- package/dist/schemas/unload-model.d.ts +19 -0
- package/dist/schemas/unload-model.js +13 -0
- package/dist/schemas/whispercpp-config.d.ts +25 -0
- package/dist/schemas/whispercpp-config.js +18 -0
- package/dist/server/bare/addons/cancel.d.ts +3 -0
- package/dist/server/bare/addons/cancel.js +12 -0
- package/dist/server/bare/addons/index.d.ts +4 -0
- package/dist/server/bare/addons/index.js +3 -0
- package/dist/server/bare/addons/llamacpp/create-model.d.ts +5 -0
- package/dist/server/bare/addons/llamacpp/create-model.js +57 -0
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.d.ts +3 -0
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.js +65 -0
- package/dist/server/bare/addons/llamacpp/handlers/embed.d.ts +4 -0
- package/dist/server/bare/addons/llamacpp/handlers/embed.js +40 -0
- package/dist/server/bare/addons/llamacpp/index.d.ts +4 -0
- package/dist/server/bare/addons/llamacpp/index.js +3 -0
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.d.ts +19 -0
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +46 -0
- package/dist/server/bare/addons/load-model.d.ts +3 -0
- package/dist/server/bare/addons/load-model.js +55 -0
- package/dist/server/bare/addons/translation/create-model.d.ts +4 -0
- package/dist/server/bare/addons/translation/create-model.js +45 -0
- package/dist/server/bare/addons/translation/handlers/translate.d.ts +3 -0
- package/dist/server/bare/addons/translation/handlers/translate.js +86 -0
- package/dist/server/bare/addons/translation/index.d.ts +3 -0
- package/dist/server/bare/addons/translation/index.js +2 -0
- package/dist/server/bare/addons/unload-model.d.ts +3 -0
- package/dist/server/bare/addons/unload-model.js +20 -0
- package/dist/server/bare/addons/whispercpp/create-model.d.ts +6 -0
- package/dist/server/bare/addons/whispercpp/create-model.js +55 -0
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.d.ts +3 -0
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +42 -0
- package/dist/server/bare/addons/whispercpp/index.d.ts +3 -0
- package/dist/server/bare/addons/whispercpp/index.js +2 -0
- package/dist/server/bare/delegate-rpc-client.d.ts +4 -0
- package/dist/server/bare/delegate-rpc-client.js +70 -0
- package/dist/server/bare/hyperswarm.d.ts +7 -0
- package/dist/server/bare/hyperswarm.js +62 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +12 -0
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +6 -0
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +16 -0
- package/dist/server/bare/rag-hyperdb/handlers/search.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/search.js +15 -0
- package/dist/server/bare/rag-hyperdb/index.d.ts +5 -0
- package/dist/server/bare/rag-hyperdb/index.js +4 -0
- package/dist/server/bare/rag-hyperdb/rag-manager.d.ts +5 -0
- package/dist/server/bare/rag-hyperdb/rag-manager.js +61 -0
- package/dist/server/bare/registry/logging-stream-registry.d.ts +12 -0
- package/dist/server/bare/registry/logging-stream-registry.js +46 -0
- package/dist/server/bare/registry/model-registry.d.ts +64 -0
- package/dist/server/bare/registry/model-registry.js +95 -0
- package/dist/server/error-handlers.d.ts +4 -0
- package/dist/server/error-handlers.js +27 -0
- package/dist/server/http-server.d.ts +2 -0
- package/dist/server/http-server.js +189 -0
- package/dist/server/rpc/create-server.d.ts +4 -0
- package/dist/server/rpc/create-server.js +19 -0
- package/dist/server/rpc/handle-request.d.ts +12 -0
- package/dist/server/rpc/handle-request.js +220 -0
- package/dist/server/rpc/handlers/cancelHandler.d.ts +3 -0
- package/dist/server/rpc/handlers/cancelHandler.js +27 -0
- package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +3 -0
- package/dist/server/rpc/handlers/completion-stream-delegated.js +30 -0
- package/dist/server/rpc/handlers/completion-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/completion-stream.js +52 -0
- package/dist/server/rpc/handlers/download-asset.d.ts +3 -0
- package/dist/server/rpc/handlers/download-asset.js +21 -0
- package/dist/server/rpc/handlers/embed.d.ts +3 -0
- package/dist/server/rpc/handlers/embed.js +21 -0
- package/dist/server/rpc/handlers/index.d.ts +23 -0
- package/dist/server/rpc/handlers/index.js +22 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +31 -0
- package/dist/server/rpc/handlers/load-model/download-manager.js +88 -0
- package/dist/server/rpc/handlers/load-model/http.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model/http.js +337 -0
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +4 -0
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +332 -0
- package/dist/server/rpc/handlers/load-model/index.d.ts +4 -0
- package/dist/server/rpc/handlers/load-model/index.js +3 -0
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model/resolve.js +121 -0
- package/dist/server/rpc/handlers/load-model-delegated.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model-delegated.js +93 -0
- package/dist/server/rpc/handlers/load-model.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model.js +41 -0
- package/dist/server/rpc/handlers/logging-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/logging-stream.js +37 -0
- package/dist/server/rpc/handlers/provideHandler/connection.d.ts +3 -0
- package/dist/server/rpc/handlers/provideHandler/connection.js +25 -0
- package/dist/server/rpc/handlers/provideHandler/handler.d.ts +3 -0
- package/dist/server/rpc/handlers/provideHandler/handler.js +50 -0
- package/dist/server/rpc/handlers/provideHandler/proxy.d.ts +3 -0
- package/dist/server/rpc/handlers/provideHandler/proxy.js +22 -0
- package/dist/server/rpc/handlers/provideHandler.d.ts +2 -0
- package/dist/server/rpc/handlers/provideHandler.js +2 -0
- package/dist/server/rpc/handlers/rag.d.ts +3 -0
- package/dist/server/rpc/handlers/rag.js +67 -0
- package/dist/server/rpc/handlers/transcribe-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/transcribe-stream.js +26 -0
- package/dist/server/rpc/handlers/translate.d.ts +3 -0
- package/dist/server/rpc/handlers/translate.js +51 -0
- package/dist/server/rpc/handlers/unload-model.d.ts +3 -0
- package/dist/server/rpc/handlers/unload-model.js +20 -0
- package/dist/server/rpc/index.d.ts +3 -0
- package/dist/server/rpc/index.js +2 -0
- package/dist/server/utils/audio/decoder.d.ts +4 -0
- package/dist/server/utils/audio/decoder.js +41 -0
- package/dist/server/utils/cache.d.ts +15 -0
- package/dist/server/utils/cache.js +32 -0
- package/dist/server/utils/hash.d.ts +5 -0
- package/dist/server/utils/hash.js +11 -0
- package/dist/server/utils/index.d.ts +5 -0
- package/dist/server/utils/index.js +4 -0
- package/dist/server/utils/model-path.d.ts +5 -0
- package/dist/server/utils/model-path.js +7 -0
- package/dist/server/worker.d.ts +6 -0
- package/dist/server/worker.js +77 -0
- package/dist/utils/withTimeout.d.ts +11 -0
- package/dist/utils/withTimeout.js +37 -0
- package/package.json +129 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { loadModel, unloadModel, GTE_LARGE_FP16, ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings, } from "@qvac/sdk";
|
|
2
|
+
try {
|
|
3
|
+
console.log("🚀 RAG Workspaces with Chunking Example\n");
|
|
4
|
+
// Load model
|
|
5
|
+
const modelId = await loadModel({
|
|
6
|
+
modelSrc: GTE_LARGE_FP16,
|
|
7
|
+
modelType: "embeddings",
|
|
8
|
+
onProgress: (p) => process.stdout.write(`\rLoading: ${Math.round(p.percentage * 100)}%`),
|
|
9
|
+
});
|
|
10
|
+
console.log("\n");
|
|
11
|
+
// Medical article (will be chunked)
|
|
12
|
+
const medicalArticle = `
|
|
13
|
+
COVID-19: A Comprehensive Overview
|
|
14
|
+
|
|
15
|
+
COVID-19 is a respiratory illness caused by the SARS-CoV-2 virus, first identified in December 2019
|
|
16
|
+
in Wuhan, China. The virus spreads primarily through respiratory droplets when an infected person
|
|
17
|
+
coughs, sneezes, or talks.
|
|
18
|
+
|
|
19
|
+
Common symptoms include fever, cough, fatigue, and loss of taste or smell. Some patients may
|
|
20
|
+
experience shortness of breath, muscle aches, sore throat, and headaches. Symptoms typically
|
|
21
|
+
appear 2-14 days after exposure to the virus.
|
|
22
|
+
|
|
23
|
+
Vaccines have been developed using various technologies including mRNA, viral vector, and
|
|
24
|
+
inactivated virus approaches. These vaccines have proven effective in preventing severe illness,
|
|
25
|
+
hospitalization, and death. Booster doses are recommended to maintain immunity.
|
|
26
|
+
|
|
27
|
+
Treatment options vary based on severity. Mild cases often require only supportive care including
|
|
28
|
+
rest and hydration. Severe cases may require hospitalization, oxygen therapy, and antiviral
|
|
29
|
+
medications such as remdesivir or Paxlovid.
|
|
30
|
+
`;
|
|
31
|
+
// Tech documents (shorter, won't be chunked)
|
|
32
|
+
const techDocs = [
|
|
33
|
+
"Artificial intelligence is transforming industries through automation and advanced data analysis capabilities.",
|
|
34
|
+
"Deep learning neural networks enable breakthroughs in computer vision and natural language processing.",
|
|
35
|
+
];
|
|
36
|
+
// Save medical article with chunking
|
|
37
|
+
console.log("📚 Saving medical article with chunking...");
|
|
38
|
+
const medicalResult = await ragSaveEmbeddings({
|
|
39
|
+
modelId,
|
|
40
|
+
workspace: "medical",
|
|
41
|
+
documents: medicalArticle,
|
|
42
|
+
chunk: true,
|
|
43
|
+
chunkOpts: {
|
|
44
|
+
chunkSize: 30,
|
|
45
|
+
chunkOverlap: 10,
|
|
46
|
+
chunkStrategy: "paragraph",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
console.log(`✅ Created ${medicalResult.processed.length} chunks from medical article`);
|
|
50
|
+
// Save tech docs without chunking
|
|
51
|
+
console.log("\n📚 Saving tech documents...");
|
|
52
|
+
const techResult = await ragSaveEmbeddings({
|
|
53
|
+
modelId,
|
|
54
|
+
workspace: "technology",
|
|
55
|
+
documents: techDocs,
|
|
56
|
+
chunk: false,
|
|
57
|
+
});
|
|
58
|
+
console.log(`✅ Saved ${techResult.processed.length} tech documents`);
|
|
59
|
+
// Test searches
|
|
60
|
+
const searches = [
|
|
61
|
+
{ workspace: "medical", query: "COVID symptoms fever", label: "Medical" },
|
|
62
|
+
{ workspace: "medical", query: "vaccine technology", label: "Medical" },
|
|
63
|
+
{ workspace: "technology", query: "neural networks", label: "Tech" },
|
|
64
|
+
{ workspace: "technology", query: "COVID", label: "Tech (isolation test)" },
|
|
65
|
+
];
|
|
66
|
+
console.log("\n🔍 Running searches:");
|
|
67
|
+
for (const { workspace, query, label } of searches) {
|
|
68
|
+
const results = await ragSearch({ modelId, workspace, query, topK: 1 });
|
|
69
|
+
console.log(`\n${label}: "${query}"`);
|
|
70
|
+
if (results.length > 0 && results[0]) {
|
|
71
|
+
console.log(` ✓ Score: ${results[0].score.toFixed(3)}`);
|
|
72
|
+
console.log(` ✓ Match: ${results[0].content.substring(0, 80)}...`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
console.log(` ✗ No results (workspace isolation working correctly)`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Test default workspace
|
|
79
|
+
console.log("\n📁 Testing default workspace...");
|
|
80
|
+
await ragSaveEmbeddings({
|
|
81
|
+
modelId,
|
|
82
|
+
documents: ["Default workspace content for testing"],
|
|
83
|
+
chunk: false,
|
|
84
|
+
});
|
|
85
|
+
const defaultSearch = await ragSearch({
|
|
86
|
+
modelId,
|
|
87
|
+
query: "default workspace",
|
|
88
|
+
});
|
|
89
|
+
console.log(`Default workspace: ${defaultSearch?.[0]?.content === "Default workspace content for testing" ? "✅ Working" : "❌ Failed"}`);
|
|
90
|
+
// Cleanup example
|
|
91
|
+
const firstChunk = medicalResult.processed.find((p) => p.status === "fulfilled" && p.id);
|
|
92
|
+
if (firstChunk?.id) {
|
|
93
|
+
await ragDeleteEmbeddings({
|
|
94
|
+
modelId,
|
|
95
|
+
workspace: "medical",
|
|
96
|
+
ids: [firstChunk.id],
|
|
97
|
+
});
|
|
98
|
+
console.log("\n🗑️ Deleted one medical chunk");
|
|
99
|
+
}
|
|
100
|
+
await unloadModel({ modelId });
|
|
101
|
+
process.exit(0);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error("❌ Error:", error);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { loadModel, unloadModel, GTE_LARGE_FP16, ragSaveEmbeddings, ragSearch, } from "@qvac/sdk";
|
|
2
|
+
try {
|
|
3
|
+
// Get query from command line or use default
|
|
4
|
+
const query = process.argv[2] || "machine learning algorithms";
|
|
5
|
+
console.log(`🔍 Query: "${query}"`);
|
|
6
|
+
const modelId = await loadModel({
|
|
7
|
+
modelSrc: GTE_LARGE_FP16,
|
|
8
|
+
modelType: "embeddings",
|
|
9
|
+
onProgress: (progress) => {
|
|
10
|
+
console.log(`Loading model... ${progress.percentage.toFixed(1)}%`);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
const samples = [
|
|
14
|
+
"Machine learning is a subset of artificial intelligence that focuses on algorithms that can learn and make predictions from data without being explicitly programmed for every task.",
|
|
15
|
+
"Deep learning uses neural networks with multiple layers to process and learn from complex data patterns, enabling breakthroughs in image recognition and natural language processing.",
|
|
16
|
+
"Natural language processing combines computational linguistics with machine learning to help computers understand, interpret, and generate human language in a meaningful way.",
|
|
17
|
+
"Computer vision enables machines to interpret and understand visual information from the world, using techniques like image classification, object detection, and facial recognition.",
|
|
18
|
+
"Quantum computing leverages quantum mechanical phenomena to process information in fundamentally different ways than classical computers, potentially solving certain problems exponentially faster.",
|
|
19
|
+
"Blockchain technology creates decentralized, immutable ledgers that enable secure peer-to-peer transactions without requiring a central authority or intermediary.",
|
|
20
|
+
"Cloud computing delivers computing services over the internet, allowing users to access resources like storage, processing power, and applications on-demand from anywhere.",
|
|
21
|
+
"Cybersecurity protects digital systems, networks, and data from malicious attacks, unauthorized access, and various forms of cyber threats through multiple layers of defense.",
|
|
22
|
+
];
|
|
23
|
+
console.log("📚 Embedding documents...");
|
|
24
|
+
const docs = await ragSaveEmbeddings({
|
|
25
|
+
modelId,
|
|
26
|
+
documents: samples,
|
|
27
|
+
chunk: false,
|
|
28
|
+
});
|
|
29
|
+
console.log("🔍 Documents:", docs);
|
|
30
|
+
console.log("🔎 Searching for similar documents...");
|
|
31
|
+
const results = await ragSearch({
|
|
32
|
+
modelId,
|
|
33
|
+
query,
|
|
34
|
+
topK: 3,
|
|
35
|
+
});
|
|
36
|
+
console.log("\n📋 Top 3 most similar documents:");
|
|
37
|
+
results.forEach((result, index) => {
|
|
38
|
+
console.log("=".repeat(50) + " Top result:");
|
|
39
|
+
console.log(`\n${index + 1}. (Score: ${result.score})`);
|
|
40
|
+
console.log(` ${result.content}`);
|
|
41
|
+
console.log("=".repeat(100));
|
|
42
|
+
console.log();
|
|
43
|
+
});
|
|
44
|
+
await unloadModel({ modelId });
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error("❌ Error:", error);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { embed, loadModel, unloadModel, GTE_LARGE_FP16 } from "@qvac/sdk";
|
|
2
|
+
import * as lancedb from "@lancedb/lancedb";
|
|
3
|
+
import * as a from "apache-arrow";
|
|
4
|
+
try {
|
|
5
|
+
// Get query from command line or use default
|
|
6
|
+
const query = process.argv[2] || "machine learning algorithms";
|
|
7
|
+
console.log(`🔍 Query: "${query}"`);
|
|
8
|
+
const db = await lancedb.connect(".rag-lancedb");
|
|
9
|
+
const modelId = await loadModel({
|
|
10
|
+
modelSrc: GTE_LARGE_FP16,
|
|
11
|
+
modelType: "embeddings",
|
|
12
|
+
onProgress: (progress) => {
|
|
13
|
+
console.log(`Loading model... ${progress.percentage.toFixed(1)}%`);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const samples = [
|
|
17
|
+
{
|
|
18
|
+
id: 1,
|
|
19
|
+
text: "Machine learning is a subset of artificial intelligence that focuses on algorithms that can learn and make predictions from data without being explicitly programmed for every task.",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: 2,
|
|
23
|
+
text: "Deep learning uses neural networks with multiple layers to process and learn from complex data patterns, enabling breakthroughs in image recognition and natural language processing.",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 3,
|
|
27
|
+
text: "Natural language processing combines computational linguistics with machine learning to help computers understand, interpret, and generate human language in a meaningful way.",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 4,
|
|
31
|
+
text: "Computer vision enables machines to interpret and understand visual information from the world, using techniques like image classification, object detection, and facial recognition.",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 5,
|
|
35
|
+
text: "Quantum computing leverages quantum mechanical phenomena to process information in fundamentally different ways than classical computers, potentially solving certain problems exponentially faster.",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 6,
|
|
39
|
+
text: "Blockchain technology creates decentralized, immutable ledgers that enable secure peer-to-peer transactions without requiring a central authority or intermediary.",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 7,
|
|
43
|
+
text: "Cloud computing delivers computing services over the internet, allowing users to access resources like storage, processing power, and applications on-demand from anywhere.",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 8,
|
|
47
|
+
text: "Cybersecurity protects digital systems, networks, and data from malicious attacks, unauthorized access, and various forms of cyber threats through multiple layers of defense.",
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
const schema = new a.Schema([
|
|
51
|
+
new a.Field("id", new a.Int32()),
|
|
52
|
+
new a.Field("text", new a.Utf8()),
|
|
53
|
+
new a.Field("vector", new a.FixedSizeList(1024, new a.Field("item", new a.Float32()))),
|
|
54
|
+
]);
|
|
55
|
+
// Create or recreate the table
|
|
56
|
+
try {
|
|
57
|
+
await db.dropTable("documents");
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.warn(`Table doesn't exist, no need to drop: ${String(e)}`);
|
|
61
|
+
}
|
|
62
|
+
const documentsTable = await db.createEmptyTable("documents", schema);
|
|
63
|
+
console.log("📚 Embedding documents...");
|
|
64
|
+
const documents = [];
|
|
65
|
+
for (const sample of samples) {
|
|
66
|
+
const embedding = await embed({ modelId, text: sample.text });
|
|
67
|
+
const record = {
|
|
68
|
+
id: sample.id,
|
|
69
|
+
text: sample.text,
|
|
70
|
+
vector: embedding,
|
|
71
|
+
};
|
|
72
|
+
documents.push(record);
|
|
73
|
+
}
|
|
74
|
+
await documentsTable.add(documents);
|
|
75
|
+
console.log("🔎 Searching for similar documents...");
|
|
76
|
+
const queryEmbedding = await embed({ modelId, text: query });
|
|
77
|
+
const results = (await documentsTable
|
|
78
|
+
.vectorSearch(queryEmbedding)
|
|
79
|
+
.limit(1)
|
|
80
|
+
.toArray());
|
|
81
|
+
console.log("\n📋 Top 3 most similar documents:");
|
|
82
|
+
results.forEach((result, index) => {
|
|
83
|
+
console.log("=".repeat(50) + " Top result:");
|
|
84
|
+
console.log(`\n${index + 1}. (Score: ${result._distance?.toFixed(4)})`);
|
|
85
|
+
console.log(` ${result.text}`);
|
|
86
|
+
console.log("=".repeat(100));
|
|
87
|
+
console.log();
|
|
88
|
+
});
|
|
89
|
+
await unloadModel({ modelId });
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error("❌ Error:", error);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { embed, loadModel, unloadModel, GTE_LARGE_FP16 } from "@qvac/sdk";
|
|
2
|
+
import sqlite3InitModule from "@sqliteai/sqlite-wasm";
|
|
3
|
+
try {
|
|
4
|
+
// Get query from command line or use default
|
|
5
|
+
const query = process.argv[2] || "machine learning algorithms";
|
|
6
|
+
console.log(`🔍 Query: "${query}"`);
|
|
7
|
+
// Initialize SQLite with vector extension
|
|
8
|
+
const sqlite3 = await sqlite3InitModule();
|
|
9
|
+
const db = new sqlite3.oo1.DB(":memory:", "c");
|
|
10
|
+
const modelId = await loadModel({
|
|
11
|
+
modelSrc: GTE_LARGE_FP16,
|
|
12
|
+
modelType: "embeddings",
|
|
13
|
+
onProgress: (progress) => {
|
|
14
|
+
console.log(`Loading model... ${progress.percentage.toFixed(1)}%`);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const samples = [
|
|
18
|
+
{
|
|
19
|
+
id: 1,
|
|
20
|
+
text: "Machine learning is a subset of artificial intelligence that focuses on algorithms that can learn and make predictions from data without being explicitly programmed for every task.",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 2,
|
|
24
|
+
text: "Deep learning uses neural networks with multiple layers to process and learn from complex data patterns, enabling breakthroughs in image recognition and natural language processing.",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 3,
|
|
28
|
+
text: "Natural language processing combines computational linguistics with machine learning to help computers understand, interpret, and generate human language in a meaningful way.",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 4,
|
|
32
|
+
text: "Computer vision enables machines to interpret and understand visual information from the world, using techniques like image classification, object detection, and facial recognition.",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 5,
|
|
36
|
+
text: "Quantum computing leverages quantum mechanical phenomena to process information in fundamentally different ways than classical computers, potentially solving certain problems exponentially faster.",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 6,
|
|
40
|
+
text: "Blockchain technology creates decentralized, immutable ledgers that enable secure peer-to-peer transactions without requiring a central authority or intermediary.",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 7,
|
|
44
|
+
text: "Cloud computing delivers computing services over the internet, allowing users to access resources like storage, processing power, and applications on-demand from anywhere.",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 8,
|
|
48
|
+
text: "Cybersecurity protects digital systems, networks, and data from malicious attacks, unauthorized access, and various forms of cyber threats through multiple layers of defense.",
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
// Create table for documents with vector storage
|
|
52
|
+
db.exec(`
|
|
53
|
+
CREATE TABLE IF NOT EXISTS documents (
|
|
54
|
+
id INTEGER PRIMARY KEY,
|
|
55
|
+
text TEXT NOT NULL,
|
|
56
|
+
embedding BLOB NOT NULL
|
|
57
|
+
)
|
|
58
|
+
`);
|
|
59
|
+
console.log("📚 Embedding documents...");
|
|
60
|
+
for (const sample of samples) {
|
|
61
|
+
const embedding = await embed({ modelId, text: sample.text });
|
|
62
|
+
db.exec({
|
|
63
|
+
sql: "INSERT INTO documents VALUES (?, ?, vector_as_f32(?))",
|
|
64
|
+
bind: [sample.id, sample.text, JSON.stringify(embedding)],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Initialize and optimize vector index
|
|
68
|
+
db.exec(`SELECT vector_init('documents', 'embedding', 'type=FLOAT32,dimension=1024')`);
|
|
69
|
+
// Quantize vectors
|
|
70
|
+
db.exec(`SELECT vector_quantize('documents', 'embedding')`);
|
|
71
|
+
// [Optional] Preload quantized vectors in memory for optimal performance
|
|
72
|
+
db.exec(`SELECT vector_quantize_preload('documents', 'embedding')`);
|
|
73
|
+
// Search for similar documents
|
|
74
|
+
console.log("🔎 Searching for similar documents...");
|
|
75
|
+
const queryEmbedding = await embed({ modelId, text: query });
|
|
76
|
+
const results = [];
|
|
77
|
+
// Perform vector search
|
|
78
|
+
db.exec({
|
|
79
|
+
sql: `
|
|
80
|
+
SELECT d.id, d.text, v.distance
|
|
81
|
+
FROM documents d
|
|
82
|
+
JOIN vector_quantize_scan('documents', 'embedding', vector_as_f32(?), 3) v
|
|
83
|
+
ON d.id = v.rowid
|
|
84
|
+
`,
|
|
85
|
+
bind: [JSON.stringify(queryEmbedding)],
|
|
86
|
+
rowMode: "object",
|
|
87
|
+
callback: (row) => {
|
|
88
|
+
const typedRow = row;
|
|
89
|
+
results.push(typedRow);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
console.log("\n📋 Top 3 most similar documents:");
|
|
93
|
+
results.forEach((result, index) => {
|
|
94
|
+
console.log("=".repeat(50) + " Top result:");
|
|
95
|
+
console.log(`\n${index + 1}. [ID: ${result.id}] (Score: ${result.distance.toFixed(4)})`);
|
|
96
|
+
console.log(` ${result.text}`);
|
|
97
|
+
console.log("=".repeat(100));
|
|
98
|
+
console.log();
|
|
99
|
+
});
|
|
100
|
+
await unloadModel({ modelId });
|
|
101
|
+
db.close();
|
|
102
|
+
process.exit(0);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
console.error("❌ Error:", error);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LLAMA_3_2_1B_INST_Q4_0, downloadAsset } from "@qvac/sdk";
|
|
2
|
+
await downloadAsset({
|
|
3
|
+
assetSrc: LLAMA_3_2_1B_INST_Q4_0,
|
|
4
|
+
seed: true,
|
|
5
|
+
onProgress: (progress) => {
|
|
6
|
+
console.log(progress);
|
|
7
|
+
},
|
|
8
|
+
})
|
|
9
|
+
.then(() => {
|
|
10
|
+
console.log("✅ Model loaded and seeding started!");
|
|
11
|
+
console.log("📡 Seeding service is running... Press Ctrl+C to stop");
|
|
12
|
+
})
|
|
13
|
+
.catch((error) => {
|
|
14
|
+
console.error("❌ Error:", error);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
|
17
|
+
process.on("SIGINT", () => {
|
|
18
|
+
console.log("\n🛑 Seeding service stopped");
|
|
19
|
+
process.exit(0);
|
|
20
|
+
});
|
|
21
|
+
process.stdin.resume();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { loadModel, translate, unloadModel, MARIAN_EN_HI_INDIC_1B_Q4_0, } from "@qvac/sdk";
|
|
2
|
+
try {
|
|
3
|
+
const modelId = await loadModel({
|
|
4
|
+
modelSrc: MARIAN_EN_HI_INDIC_1B_Q4_0,
|
|
5
|
+
modelType: "nmt",
|
|
6
|
+
onProgress: (progress) => {
|
|
7
|
+
console.log(progress);
|
|
8
|
+
},
|
|
9
|
+
modelConfig: {
|
|
10
|
+
from: "eng_Latn",
|
|
11
|
+
to: "hin_Deva",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
console.log(`✅ Model loaded: ${modelId}`);
|
|
15
|
+
const text = "Hello, how are you today?";
|
|
16
|
+
const result = translate({
|
|
17
|
+
modelId,
|
|
18
|
+
text,
|
|
19
|
+
modelType: "nmt",
|
|
20
|
+
stream: false,
|
|
21
|
+
});
|
|
22
|
+
const translatedText = await result.text;
|
|
23
|
+
console.log(`Translated text EN -> HI: ${text} -> "${translatedText}"`);
|
|
24
|
+
await unloadModel({ modelId });
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error("❌ Error:", error);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { translate, loadModel, unloadModel, SALAMANDRATA_2B_INST_Q8, } from "@qvac/sdk";
|
|
2
|
+
try {
|
|
3
|
+
const modelId = await loadModel({
|
|
4
|
+
modelSrc: SALAMANDRATA_2B_INST_Q8,
|
|
5
|
+
modelType: "llm",
|
|
6
|
+
onProgress: (progress) => {
|
|
7
|
+
console.log(progress);
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
console.log(`✅ Model loaded: ${modelId}`);
|
|
11
|
+
// With explicit source language
|
|
12
|
+
const engText = "bank";
|
|
13
|
+
const resultExplicit = translate({
|
|
14
|
+
modelId,
|
|
15
|
+
text: engText,
|
|
16
|
+
from: "en",
|
|
17
|
+
to: "es",
|
|
18
|
+
modelType: "llm",
|
|
19
|
+
context: "Use formal language, letter for financial institution",
|
|
20
|
+
stream: false,
|
|
21
|
+
});
|
|
22
|
+
const translatedTextExplicit = await resultExplicit.text;
|
|
23
|
+
console.log(`${engText} -> "${translatedTextExplicit}"`); // "banco" (not "orilla")
|
|
24
|
+
await unloadModel({ modelId, clearStorage: false });
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error("❌ Error:", error);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { translate, loadModel, SALAMANDRATA_2B_INST_Q4 } from "@qvac/sdk";
|
|
2
|
+
try {
|
|
3
|
+
const modelId = await loadModel({
|
|
4
|
+
modelSrc: SALAMANDRATA_2B_INST_Q4,
|
|
5
|
+
modelType: "llm",
|
|
6
|
+
onProgress: (progress) => {
|
|
7
|
+
console.log(progress);
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
// With explicit source language
|
|
11
|
+
const engText = "Hello, how are you today?";
|
|
12
|
+
const resultExplicit = translate({
|
|
13
|
+
modelId,
|
|
14
|
+
text: engText,
|
|
15
|
+
from: "en",
|
|
16
|
+
to: "it",
|
|
17
|
+
modelType: "llm",
|
|
18
|
+
stream: false,
|
|
19
|
+
});
|
|
20
|
+
// With autodetection
|
|
21
|
+
const espText = "Hola, como estas?";
|
|
22
|
+
const resultAutodetect = translate({
|
|
23
|
+
modelId,
|
|
24
|
+
text: espText,
|
|
25
|
+
to: "en",
|
|
26
|
+
modelType: "llm",
|
|
27
|
+
stream: false,
|
|
28
|
+
});
|
|
29
|
+
const translatedTextExplicit = await resultExplicit.text;
|
|
30
|
+
const translatedTextAutodetect = await resultAutodetect.text;
|
|
31
|
+
console.log(`Explicit source: ${engText} -> "${translatedTextExplicit}"`);
|
|
32
|
+
console.log(`Autodetected source: ${espText} -> "${translatedTextAutodetect}"`);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error("❌ Error:", error);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { loadModel, translate, unloadModel, MARIAN_OPUS_EN_IT_Q0F32, } from "@qvac/sdk";
|
|
2
|
+
try {
|
|
3
|
+
const modelId = await loadModel({
|
|
4
|
+
modelSrc: MARIAN_OPUS_EN_IT_Q0F32,
|
|
5
|
+
modelType: "nmt",
|
|
6
|
+
modelConfig: {
|
|
7
|
+
from: "en",
|
|
8
|
+
to: "it",
|
|
9
|
+
},
|
|
10
|
+
onProgress: (progress) => {
|
|
11
|
+
console.log(progress);
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
console.log(`✅ Model loaded: ${modelId}`);
|
|
15
|
+
const text = "Hello, how are you today?";
|
|
16
|
+
const result = translate({
|
|
17
|
+
modelId,
|
|
18
|
+
text,
|
|
19
|
+
modelType: "nmt",
|
|
20
|
+
stream: false,
|
|
21
|
+
});
|
|
22
|
+
const translatedText = await result.text;
|
|
23
|
+
console.log(`Translated text EN -> IT: ${text} -> "${translatedText}"`);
|
|
24
|
+
await unloadModel({ modelId });
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error("❌ Error:", error);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { loadModel, translate, MARIAN_OPUS_EN_IT_Q0F32, unloadModel, } from "@qvac/sdk";
|
|
2
|
+
try {
|
|
3
|
+
const modelId = await loadModel({
|
|
4
|
+
modelSrc: MARIAN_OPUS_EN_IT_Q0F32,
|
|
5
|
+
modelType: "nmt",
|
|
6
|
+
modelConfig: {
|
|
7
|
+
from: "en",
|
|
8
|
+
to: "it",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
console.log(`✅ Model loaded: ${modelId}`);
|
|
12
|
+
const text = "Hello, how are you today? I hope you are having a wonderful day!";
|
|
13
|
+
console.log("\n--- Streaming Translation ---");
|
|
14
|
+
const streamResult = translate({
|
|
15
|
+
modelId,
|
|
16
|
+
text,
|
|
17
|
+
modelType: "nmt",
|
|
18
|
+
stream: true,
|
|
19
|
+
});
|
|
20
|
+
process.stdout.write("Translated text EN -> IT: ");
|
|
21
|
+
for await (const token of streamResult.tokenStream) {
|
|
22
|
+
process.stdout.write(token);
|
|
23
|
+
}
|
|
24
|
+
console.log();
|
|
25
|
+
const stats = await streamResult.stats;
|
|
26
|
+
if (stats) {
|
|
27
|
+
console.log(`Processing stats:`, stats);
|
|
28
|
+
}
|
|
29
|
+
await unloadModel({ modelId, clearStorage: false });
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error("❌ Error:", error);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { loadModel, unloadModel, transcribe, WHISPER_TINY, VAD_SILERO_5_1_2, } from "@qvac/sdk";
|
|
2
|
+
// Parse command line arguments
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
if (!args[0]) {
|
|
5
|
+
console.error("Usage: bun run examples/whispercpp-filesystem.ts <wav-file-path>");
|
|
6
|
+
process.exit(1);
|
|
7
|
+
}
|
|
8
|
+
const audioFilePath = args[0];
|
|
9
|
+
try {
|
|
10
|
+
console.log("🎤 Starting Whisper transcription example...");
|
|
11
|
+
// Load the Whisper model with VAD
|
|
12
|
+
console.log("📥 Loading Whisper model...");
|
|
13
|
+
const modelId = await loadModel({
|
|
14
|
+
modelSrc: WHISPER_TINY,
|
|
15
|
+
modelType: "whisper",
|
|
16
|
+
vadModelSrc: VAD_SILERO_5_1_2,
|
|
17
|
+
modelConfig: {
|
|
18
|
+
mode: "caption",
|
|
19
|
+
output_format: "plaintext",
|
|
20
|
+
min_seconds: 2,
|
|
21
|
+
max_seconds: 6,
|
|
22
|
+
audio_format: "f32le",
|
|
23
|
+
},
|
|
24
|
+
onProgress: (progress) => {
|
|
25
|
+
console.log(progress);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
console.log(`✅ Whisper model loaded with ID: ${modelId}`);
|
|
29
|
+
// Perform transcription
|
|
30
|
+
console.log("🎧 Transcribing audio...");
|
|
31
|
+
const text = await transcribe({ modelId, audioChunk: audioFilePath });
|
|
32
|
+
console.log("📝 Transcription result:");
|
|
33
|
+
console.log(text);
|
|
34
|
+
// Unload the model when done
|
|
35
|
+
console.log("🧹 Unloading Whisper model...");
|
|
36
|
+
await unloadModel({ modelId });
|
|
37
|
+
console.log("✅ Whisper model unloaded successfully");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error("❌ Error:", error);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|