diff --git a/packages/sdk/bun.lock b/packages/sdk/bun.lock index 3fe9328158..5e902f6b99 100644 --- a/packages/sdk/bun.lock +++ b/packages/sdk/bun.lock @@ -17,7 +17,7 @@ "@qvac/registry-client": "^0.4.1", "@qvac/transcription-parakeet": "^0.3.1", "@qvac/transcription-whispercpp": "^0.6.1", - "@qvac/translation-nmtcpp": "^1.0.1", + "@qvac/translation-nmtcpp": "^2.0.1", "@qvac/tts-onnx": "^0.8.2", "fast-safe-stringify": "2.1.1", "which-runtime": "^1.3.2", @@ -544,7 +544,7 @@ "@qvac/transcription-whispercpp": ["@qvac/transcription-whispercpp@0.6.1", "", { "dependencies": { "@qvac/decoder-audio": "^0.3.3", "@qvac/error": "^0.1.0", "@qvac/infer-base": "^0.4.0", "@qvac/logging": "^0.1.0", "bare-channel": "^5.2.2", "bare-ffmpeg": "^1.0.0-32", "bare-node-worker-threads": "^1.0.0", "bare-path": "^3.0.0", "bare-stream": "^2.7.0", "bare-worker": "^4.1.0", "path": "npm:bare-path", "process": "npm:bare-process@^4.2.2", "stream": "npm:bare-node-stream", "worker_threads": "npm:bare-node-worker-threads@^1.0.0" } }, "sha512-GrOKYjtCAJGVnCssDpoKgMD2S7O6zdOG2rFnR1+Almc5/+924U08peR3eQEuvTiP0+No6X5Aa0CIx0lGsOFBig=="], - "@qvac/translation-nmtcpp": ["@qvac/translation-nmtcpp@1.0.1", "", { "dependencies": { "@qvac/dl-hyperdrive": "^0.1.0", "@qvac/error": "^0.1.0", "@qvac/infer-base": "^0.2.0", "bare-path": "^3.0.0" } }, "sha512-KMF/8A2b7SxSMTsHxSZWH/YTFDyW1LSUEKs/x7f4P/zZTrqJYzZqOkEvxe9IS27kiz7dRAh7i3Q1hyvCnLdzIg=="], + "@qvac/translation-nmtcpp": ["@qvac/translation-nmtcpp@2.0.2", "", { "dependencies": { "@qvac/error": "^0.1.0", "@qvac/infer-base": "^0.4.0", "@qvac/logging": "^0.1.0" } }, "sha512-U+2ZsX9fWLTi4IctxFRJSV7ZAazCIENXQhievHBB3v5Z/3VlCeixxZ5nEpE/0tHaha1ZuknUiepLxkzklrhi/w=="], "@qvac/tts-onnx": ["@qvac/tts-onnx@0.8.2", "", { "dependencies": { "@qvac/error": "^0.1.0", "@qvac/infer-base": "^0.4.0", "@qvac/onnx": "^0.14.0", "bare-fs": "^4.5.1", "bare-path": "^3.0.0" } }, "sha512-/x6T4aGrHnBpndBZZN9W9FHQmjb+X7uXp1AQv+mi4dJai4XNxhahh7tK8OCS5Z3HdB/Iv/6YZ2PL0wnVf+OgVQ=="], @@ -2566,7 +2566,7 @@ "@qvac/transcription-whispercpp/@qvac/infer-base": ["@qvac/infer-base@0.4.0", "", { "dependencies": { "@qvac/error": "^0.1.0", "@qvac/logging": "^0.1.0", "bare-events": "2.4.2", "bare-os": "^3.2.0", "bare-path": "^3.0.0" }, "optionalDependencies": { "@qvac/diagnostics": "^0.1.0" }, "peerDependencies": { "@qvac/dl-hyperdrive": "^0.1.0" } }, "sha512-KoD4PrNzcScFjuLdGSTwtN/i10tMuwpRUW9g5lIiIaoR4s36NHwkfcxjyQDlHFlXkYjf3p3IpWXJgKOSo3jAqg=="], - "@qvac/translation-nmtcpp/@qvac/infer-base": ["@qvac/infer-base@0.2.2", "", { "dependencies": { "@qvac/error": "^0.1.0", "@qvac/logging": "^0.1.0", "bare-events": "2.4.2", "bare-os": "^3.2.0", "bare-path": "^3.0.0" }, "peerDependencies": { "@qvac/dl-hyperdrive": "^0.1.0" } }, "sha512-8D/5PRIy/A+Uhg1ZSoJMu5FSPDHdrMKZoPnAzTZMceikTj+BWwTV//j8pXbRABsjrFbqBegvr/LujirC9I2cRQ=="], + "@qvac/translation-nmtcpp/@qvac/infer-base": ["@qvac/infer-base@0.4.0", "", { "dependencies": { "@qvac/error": "^0.1.0", "@qvac/logging": "^0.1.0", "bare-events": "2.4.2", "bare-os": "^3.2.0", "bare-path": "^3.0.0" }, "optionalDependencies": { "@qvac/diagnostics": "^0.1.0" }, "peerDependencies": { "@qvac/dl-hyperdrive": "^0.1.0" } }, "sha512-KoD4PrNzcScFjuLdGSTwtN/i10tMuwpRUW9g5lIiIaoR4s36NHwkfcxjyQDlHFlXkYjf3p3IpWXJgKOSo3jAqg=="], "@qvac/tts-onnx/@qvac/infer-base": ["@qvac/infer-base@0.4.0", "", { "dependencies": { "@qvac/error": "^0.1.0", "@qvac/logging": "^0.1.0", "bare-events": "2.4.2", "bare-os": "^3.2.0", "bare-path": "^3.0.0" }, "optionalDependencies": { "@qvac/diagnostics": "^0.1.0" }, "peerDependencies": { "@qvac/dl-hyperdrive": "^0.1.0" } }, "sha512-KoD4PrNzcScFjuLdGSTwtN/i10tMuwpRUW9g5lIiIaoR4s36NHwkfcxjyQDlHFlXkYjf3p3IpWXJgKOSo3jAqg=="], diff --git a/packages/sdk/package.json b/packages/sdk/package.json index ead5acf646..5e8b8b7118 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -185,7 +185,7 @@ "@qvac/registry-client": "^0.4.1", "@qvac/transcription-parakeet": "^0.3.1", "@qvac/transcription-whispercpp": "^0.6.1", - "@qvac/translation-nmtcpp": "^1.0.1", + "@qvac/translation-nmtcpp": "^2.0.1", "@qvac/tts-onnx": "^0.8.2", "fast-safe-stringify": "2.1.1", "which-runtime": "^1.3.2", diff --git a/packages/sdk/server/bare/plugins/nmtcpp-translation/plugin.ts b/packages/sdk/server/bare/plugins/nmtcpp-translation/plugin.ts index a15f302406..b98e82799b 100644 --- a/packages/sdk/server/bare/plugins/nmtcpp-translation/plugin.ts +++ b/packages/sdk/server/bare/plugins/nmtcpp-translation/plugin.ts @@ -1,7 +1,7 @@ import nmtAddonLogging from "@qvac/translation-nmtcpp/addonLogging"; import TranslationNmtcpp, { type TranslationNmtcppConfig, - type Loader, + type TranslationNmtcppFiles, } from "@qvac/translation-nmtcpp"; import { definePlugin, @@ -19,10 +19,7 @@ import { type ResolveResult, } from "@/schemas"; import { createStreamLogger, registerAddonLogger } from "@/logging"; -import { parseModelPath } from "@/server/utils"; -import FilesystemDL from "@qvac/dl-filesystem"; import { ModelLoadFailedError } from "@/utils/errors-server"; -import { asLoader } from "@/server/bare/utils/loader-adapter"; import { translate } from "@/server/bare/ops/translate"; import { attachModelExecutionMs } from "@/profiling/model-execution"; @@ -72,8 +69,6 @@ function createNmtModel( pivotSrcVocabPath?: string, pivotDstVocabPath?: string, ) { - const { dirPath, basePath } = parseModelPath(modelPath); - const loader = new FilesystemDL({ dirPath }); const logger = createStreamLogger(modelId, ModelType.nmtcppTranslation); registerAddonLogger(modelId, ModelType.nmtcppTranslation, logger); @@ -92,17 +87,13 @@ function createNmtModel( topp, } = nmtConfig; - const args = { - loader: asLoader(loader), - logger, - modelName: basePath, - diskPath: dirPath, - opts: { stats: true }, - params: { - mode, - srcLang: from, - dstLang: to, - }, + const files: TranslationNmtcppFiles = { + model: modelPath, + ...(srcVocabPath && { srcVocab: srcVocabPath }), + ...(dstVocabPath && { dstVocab: dstVocabPath }), + ...(pivotModelPath && { pivotModel: pivotModelPath }), + ...(pivotSrcVocabPath && { pivotSrcVocab: pivotSrcVocabPath }), + ...(pivotDstVocabPath && { pivotDstVocab: pivotDstVocabPath }), }; const generationParams = { @@ -117,38 +108,31 @@ function createNmtModel( }; const config: TranslationNmtcppConfig = { - modelType: TranslationNmtcpp.ModelTypes[engine], + modelType: TranslationNmtcpp.ModelTypes[engine as keyof typeof TranslationNmtcpp.ModelTypes], ...generationParams, ...(nmtConfig.engine === "Bergamot" && { - ...(srcVocabPath && { srcVocabPath }), - ...(dstVocabPath && { dstVocabPath }), ...(nmtConfig.normalize !== undefined && { normalize: nmtConfig.normalize, }), - // Add pivot model configuration if present ...(nmtConfig.pivotModel && { - bergamotPivotModel: (() => { + pivotConfig: (() => { // eslint-disable-next-line @typescript-eslint/no-unused-vars - const {modelSrc, dstVocabSrc, srcVocabSrc, ...config} = nmtConfig.pivotModel - const { dirPath, basePath } = parseModelPath(pivotModelPath!); - return { - loader: asLoader(new FilesystemDL({ dirPath })), - modelName: basePath, - diskPath: dirPath, - config: { - ...config, - srcVocabPath: pivotSrcVocabPath, - dstVocabPath: pivotDstVocabPath - } - }; + const { modelSrc, dstVocabSrc, srcVocabSrc, ...pivotGenConfig } = nmtConfig.pivotModel; + return pivotGenConfig; })(), }), }), }; - const model = new TranslationNmtcpp(args, config); + const model = new TranslationNmtcpp({ + files, + params: { mode, srcLang: from, dstLang: to }, + config, + logger, + opts: { stats: true }, + }); - return { model, loader }; + return { model, loader: null }; } export const nmtPlugin = definePlugin({