@qvac/sdk 0.9.2 → 0.10.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/NOTICE +15 -68
- package/dist/client/api/cancel.d.ts +1 -1
- package/dist/client/api/cancel.js +1 -1
- package/dist/client/api/completion-stream.d.ts +51 -12
- package/dist/client/api/completion-stream.js +129 -56
- package/dist/client/api/delete-cache.d.ts +1 -0
- package/dist/client/api/delete-cache.js +1 -0
- package/dist/client/api/diffusion.d.ts +17 -2
- package/dist/client/api/diffusion.js +21 -4
- package/dist/client/api/embed.d.ts +4 -0
- package/dist/client/api/finetune.d.ts +21 -0
- package/dist/client/api/get-loaded-model-info.d.ts +25 -0
- package/dist/client/api/get-loaded-model-info.js +36 -0
- package/dist/client/api/get-model-info.d.ts +9 -1
- package/dist/client/api/get-model-info.js +8 -0
- package/dist/client/api/heartbeat.d.ts +2 -2
- package/dist/client/api/heartbeat.js +2 -2
- package/dist/client/api/index.d.ts +3 -1
- package/dist/client/api/index.js +3 -1
- package/dist/client/api/invoke-plugin.d.ts +16 -0
- package/dist/client/api/invoke-plugin.js +16 -0
- package/dist/client/api/load-model.d.ts +36 -3
- package/dist/client/api/load-model.js +31 -10
- package/dist/client/api/provide.d.ts +11 -5
- package/dist/client/api/provide.js +11 -6
- package/dist/client/api/rag.d.ts +9 -0
- package/dist/client/api/rag.js +9 -0
- package/dist/client/api/registry.d.ts +26 -0
- package/dist/client/api/registry.js +26 -0
- package/dist/client/api/resume.d.ts +20 -4
- package/dist/client/api/resume.js +20 -4
- package/dist/client/api/state.d.ts +23 -0
- package/dist/client/api/state.js +29 -0
- package/dist/client/api/stop-provider.d.ts +11 -5
- package/dist/client/api/stop-provider.js +11 -5
- package/dist/client/api/suspend.d.ts +21 -3
- package/dist/client/api/suspend.js +21 -3
- package/dist/client/api/text-to-speech.d.ts +64 -6
- package/dist/client/api/text-to-speech.js +423 -47
- package/dist/client/api/transcribe.d.ts +29 -4
- package/dist/client/api/transcribe.js +86 -28
- package/dist/client/api/translate.d.ts +1 -0
- package/dist/client/api/translate.js +1 -0
- package/dist/client/rpc/bare-client.js +22 -1
- package/dist/client/rpc/expo-rpc-client.d.ts +1 -1
- package/dist/client/rpc/expo-rpc-client.js +96 -4
- package/dist/client/rpc/node-rpc-client.js +36 -0
- package/dist/examples/audio/mic-input.d.ts +9 -0
- package/dist/examples/audio/mic-input.js +111 -0
- package/dist/examples/completion-events.d.ts +18 -0
- package/dist/examples/completion-events.js +79 -0
- package/dist/examples/delegated-inference/composite.js +12 -18
- package/dist/examples/delegated-inference/consumer-profiled.js +4 -11
- package/dist/examples/delegated-inference/consumer.js +8 -13
- package/dist/examples/delegated-inference/provider.js +11 -16
- package/dist/examples/diffusion-flux2-klein-img2img.d.ts +2 -0
- package/dist/examples/diffusion-flux2-klein-img2img.js +60 -0
- package/dist/examples/diffusion-flux2-klein.js +1 -0
- package/dist/examples/diffusion-img2img.d.ts +2 -0
- package/dist/examples/diffusion-img2img.js +49 -0
- package/dist/examples/diffusion-txt2img.js +2 -1
- package/dist/examples/kv-cache-example.js +11 -12
- package/dist/examples/llamacpp-cache.d.ts +2 -0
- package/dist/examples/llamacpp-cache.js +107 -0
- package/dist/examples/llamacpp-dynamic-tools.d.ts +2 -0
- package/dist/examples/llamacpp-dynamic-tools.js +144 -0
- package/dist/examples/llamacpp-native-tools.js +2 -8
- package/dist/examples/llamacpp-structured-output.d.ts +2 -0
- package/dist/examples/llamacpp-structured-output.js +106 -0
- package/dist/examples/llamacpp-tools-pythonic.d.ts +2 -0
- package/dist/examples/llamacpp-tools-pythonic.js +69 -0
- package/dist/examples/plugins.js +4 -4
- package/dist/examples/suspend-resume.js +21 -4
- package/dist/examples/transcription/parakeet-microphone-record.js +6 -33
- package/dist/examples/transcription/whispercpp-filesystem-streaming.js +7 -5
- package/dist/examples/transcription/whispercpp-filesystem.js +12 -3
- package/dist/examples/transcription/whispercpp-microphone-record.js +6 -29
- package/dist/examples/translation/translation-stream.js +5 -5
- package/dist/examples/tts/llm-to-tts-streaming.d.ts +16 -0
- package/dist/examples/tts/llm-to-tts-streaming.js +143 -0
- package/dist/examples/tts/supertonic-multilingual.js +3 -3
- package/dist/examples/tts/supertonic.js +3 -3
- package/dist/examples/tts/utils.d.ts +11 -1
- package/dist/examples/tts/utils.js +70 -17
- package/dist/examples/voice-assistant/voice-assistant.d.ts +2 -0
- package/dist/examples/voice-assistant/voice-assistant.js +207 -0
- package/dist/expo/plugins/withMobileBundle.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/logging/logger.d.ts +11 -0
- package/dist/logging/logger.js +11 -0
- package/dist/logging/types.d.ts +18 -0
- package/dist/models/registry/models.d.ts +6620 -6185
- package/dist/models/registry/models.js +6296 -5318
- package/dist/models/update-models/codegen.js +84 -23
- package/dist/models/update-models/companions.d.ts +18 -0
- package/dist/models/update-models/companions.js +175 -0
- package/dist/models/update-models/naming.js +0 -25
- package/dist/models/update-models/registry.js +4 -2
- package/dist/models/update-models/types.d.ts +37 -9
- package/dist/profiling/index.d.ts +49 -0
- package/dist/profiling/index.js +49 -0
- package/dist/schemas/cancel.d.ts +6 -2
- package/dist/schemas/cancel.js +14 -7
- package/dist/schemas/common.d.ts +353 -271
- package/dist/schemas/common.js +26 -5
- package/dist/schemas/completion-event.d.ts +225 -0
- package/dist/schemas/completion-event.js +79 -0
- package/dist/schemas/completion-stream.d.ts +122 -31
- package/dist/schemas/completion-stream.js +137 -36
- package/dist/schemas/delegate.d.ts +0 -2
- package/dist/schemas/delegate.js +25 -6
- package/dist/schemas/download-asset.d.ts +5 -5
- package/dist/schemas/embed.js +21 -9
- package/dist/schemas/engine-addon-map.d.ts +11 -1
- package/dist/schemas/engine-addon-map.js +2 -2
- package/dist/schemas/get-loaded-model-info.d.ts +52 -0
- package/dist/schemas/get-loaded-model-info.js +44 -0
- package/dist/schemas/get-model-info.d.ts +2 -2
- package/dist/schemas/get-model-info.js +103 -32
- package/dist/schemas/heartbeat.d.ts +0 -1
- package/dist/schemas/index.d.ts +4 -1
- package/dist/schemas/index.js +4 -1
- package/dist/schemas/llamacpp-config.d.ts +14 -4
- package/dist/schemas/llamacpp-config.js +5 -0
- package/dist/schemas/load-model.d.ts +3233 -1260
- package/dist/schemas/load-model.js +23 -16
- package/dist/schemas/model-src-utils.d.ts +7 -6
- package/dist/schemas/model-src-utils.js +27 -1
- package/dist/schemas/model-types.d.ts +4 -4
- package/dist/schemas/ocr.d.ts +1 -1
- package/dist/schemas/plugin.d.ts +27 -3
- package/dist/schemas/plugin.js +27 -2
- package/dist/schemas/profiling.js +11 -3
- package/dist/schemas/provide.d.ts +1 -3
- package/dist/schemas/provide.js +0 -3
- package/dist/schemas/rag.d.ts +4 -4
- package/dist/schemas/registry.d.ts +10 -10
- package/dist/schemas/registry.js +36 -14
- package/dist/schemas/reload-config.d.ts +73 -7
- package/dist/schemas/sdcpp-config.d.ts +16 -8
- package/dist/schemas/sdcpp-config.js +118 -25
- package/dist/schemas/sdk-config.d.ts +116 -90
- package/dist/schemas/sdk-config.js +16 -0
- package/dist/schemas/sdk-errors-client.d.ts +3 -0
- package/dist/schemas/sdk-errors-client.js +16 -1
- package/dist/schemas/sdk-errors-server.d.ts +3 -0
- package/dist/schemas/sdk-errors-server.js +23 -0
- package/dist/schemas/state.d.ts +23 -0
- package/dist/schemas/state.js +14 -0
- package/dist/schemas/stop-provide.d.ts +0 -5
- package/dist/schemas/stop-provide.js +2 -6
- package/dist/schemas/text-to-speech.d.ts +93 -27
- package/dist/schemas/text-to-speech.js +27 -0
- package/dist/schemas/tools.d.ts +16 -0
- package/dist/schemas/tools.js +15 -0
- package/dist/schemas/transcription-config.d.ts +8 -8
- package/dist/schemas/transcription.d.ts +33 -0
- package/dist/schemas/transcription.js +9 -0
- package/dist/schemas/translate.js +59 -19
- package/dist/schemas/translation-config.d.ts +157 -133
- package/dist/schemas/translation-config.js +34 -11
- package/dist/server/bare/delegate-rpc-client.d.ts +1 -1
- package/dist/server/bare/delegate-rpc-client.js +131 -122
- package/dist/server/bare/hyperswarm.d.ts +2 -2
- package/dist/server/bare/hyperswarm.js +12 -7
- package/dist/server/bare/ops/cancel.js +7 -0
- package/dist/server/bare/ops/kv-cache-utils.d.ts +7 -10
- package/dist/server/bare/ops/kv-cache-utils.js +31 -40
- package/dist/server/bare/ops/load-model.js +0 -1
- package/dist/server/bare/ops/transcribe.d.ts +11 -4
- package/dist/server/bare/ops/transcribe.js +25 -4
- package/dist/server/bare/ops/translate.js +42 -4
- package/dist/server/bare/ops/unload-model.js +21 -19
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +1 -2
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +13 -8
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +257 -85
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +101 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +135 -0
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +79 -22
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +57 -32
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -16
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +69 -44
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +113 -94
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +1 -1
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +1 -2
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.d.ts +7 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.js +116 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +2 -3
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +71 -9
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +41 -13
- package/dist/server/bare/plugins/onnx-tts/plugin.js +48 -3
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +15 -7
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +5 -6
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +6 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +8 -5
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +13 -13
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +17 -1
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +40 -17
- package/dist/server/bare/registry/config-registry.js +14 -3
- package/dist/server/bare/registry/model-registry.d.ts +8 -10
- package/dist/server/bare/registry/model-registry.js +17 -12
- package/dist/server/bare/registry/registry-client.js +79 -19
- package/dist/server/bare/runtime-lifecycle.d.ts +2 -1
- package/dist/server/bare/runtime-lifecycle.js +13 -2
- package/dist/server/bare/types/addon-responses.d.ts +8 -3
- package/dist/server/bare/utils/transcribe-metadata.d.ts +21 -0
- package/dist/server/bare/utils/transcribe-metadata.js +28 -0
- package/dist/server/bare/utils/tts-stats.d.ts +22 -0
- package/dist/server/bare/utils/tts-stats.js +10 -0
- package/dist/server/rpc/create-server.d.ts +4 -1
- package/dist/server/rpc/create-server.js +5 -1
- package/dist/server/rpc/delegate-transport.js +36 -29
- package/dist/server/rpc/handle-request.js +28 -3
- package/dist/server/rpc/handler-registry.js +7 -1
- package/dist/server/rpc/handler-utils.d.ts +5 -0
- package/dist/server/rpc/handler-utils.js +22 -0
- package/dist/server/rpc/handlers/cancel-delegated.js +3 -5
- package/dist/server/rpc/handlers/cancelHandler.js +4 -5
- package/dist/server/rpc/handlers/completion-stream-delegated.js +14 -5
- package/dist/server/rpc/handlers/delete-cache.js +8 -3
- package/dist/server/rpc/handlers/download-asset.js +3 -24
- package/dist/server/rpc/handlers/get-loaded-model-info.d.ts +3 -0
- package/dist/server/rpc/handlers/get-loaded-model-info.js +39 -0
- package/dist/server/rpc/handlers/get-model-info.js +93 -84
- package/dist/server/rpc/handlers/heartbeat-delegated.js +2 -2
- package/dist/server/rpc/handlers/index.d.ts +6 -0
- package/dist/server/rpc/handlers/index.js +6 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +35 -9
- package/dist/server/rpc/handlers/load-model/download-manager.js +142 -38
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +5 -4
- package/dist/server/rpc/handlers/load-model/download-stats.js +49 -8
- package/dist/server/rpc/handlers/load-model/handler.js +31 -50
- package/dist/server/rpc/handlers/load-model/http.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/http.js +97 -142
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +55 -74
- package/dist/server/rpc/handlers/load-model/index.d.ts +0 -1
- package/dist/server/rpc/handlers/load-model/index.js +0 -1
- package/dist/server/rpc/handlers/load-model/registry-client-options.d.ts +27 -0
- package/dist/server/rpc/handlers/load-model/registry-client-options.js +19 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.d.ts +22 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.js +208 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.d.ts +24 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.js +114 -0
- package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -20
- package/dist/server/rpc/handlers/load-model/registry.js +109 -381
- package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +15 -0
- package/dist/server/rpc/handlers/load-model/resolve-session.js +61 -0
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/resolve.js +14 -23
- package/dist/server/rpc/handlers/load-model/types.d.ts +11 -4
- package/dist/server/rpc/handlers/load-model/types.js +28 -1
- package/dist/server/rpc/handlers/load-model-delegated.js +2 -4
- package/dist/server/rpc/handlers/plugin-dispatch.js +9 -5
- package/dist/server/rpc/handlers/plugin-invoke.js +1 -1
- package/dist/server/rpc/handlers/provideHandler/connection.js +13 -2
- package/dist/server/rpc/handlers/provideHandler/handler.js +42 -29
- package/dist/server/rpc/handlers/state.d.ts +3 -0
- package/dist/server/rpc/handlers/state.js +7 -0
- package/dist/server/rpc/handlers/stopProvideHandler.d.ts +2 -2
- package/dist/server/rpc/handlers/stopProvideHandler.js +12 -7
- package/dist/server/rpc/handlers/text-to-speech-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/text-to-speech-stream.js +4 -0
- package/dist/server/rpc/handlers/unload-model-delegated.js +3 -3
- package/dist/server/rpc/profiling/operation-metrics.js +20 -0
- package/dist/server/rpc/rpc-utils.js +1 -1
- package/dist/server/rpc/transport-selector.d.ts +3 -0
- package/dist/server/rpc/transport-selector.js +18 -0
- package/dist/server/utils/cache/auto-history.d.ts +4 -0
- package/dist/server/utils/cache/auto-history.js +22 -0
- package/dist/server/utils/{cache.d.ts → cache/paths.d.ts} +22 -5
- package/dist/server/utils/{cache.js → cache/paths.js} +36 -20
- package/dist/server/utils/cache/types.d.ts +8 -0
- package/dist/server/utils/cache/types.js +1 -0
- package/dist/server/utils/checksum.d.ts +2 -2
- package/dist/server/utils/checksum.js +1 -1
- package/dist/server/utils/clear-storage.d.ts +5 -0
- package/dist/server/utils/clear-storage.js +17 -0
- package/dist/server/utils/completion-normalizer.d.ts +17 -0
- package/dist/server/utils/completion-normalizer.js +301 -0
- package/dist/server/utils/expand-gguf-shards.d.ts +3 -0
- package/dist/server/utils/expand-gguf-shards.js +22 -0
- package/dist/server/utils/formatting.js +1 -1
- package/dist/server/utils/index.d.ts +4 -2
- package/dist/server/utils/index.js +4 -2
- package/dist/server/utils/qvac-paths.d.ts +2 -0
- package/dist/server/utils/qvac-paths.js +5 -0
- package/dist/server/utils/response-format.d.ts +3 -0
- package/dist/server/utils/response-format.js +20 -0
- package/dist/server/utils/tool-integration.d.ts +15 -4
- package/dist/server/utils/tool-integration.js +21 -41
- package/dist/server/utils/tools/dialect.d.ts +8 -0
- package/dist/server/utils/tools/dialect.js +12 -0
- package/dist/server/utils/tools/index.d.ts +3 -0
- package/dist/server/utils/tools/index.js +2 -0
- package/dist/server/utils/tools/parser.d.ts +6 -0
- package/dist/server/utils/tools/parser.js +40 -0
- package/dist/server/utils/tools/parsers/hermes.d.ts +4 -0
- package/dist/server/utils/tools/parsers/hermes.js +100 -0
- package/dist/server/utils/tools/parsers/json.d.ts +6 -0
- package/dist/server/utils/tools/parsers/json.js +115 -0
- package/dist/server/utils/tools/parsers/pythonic.d.ts +4 -0
- package/dist/server/utils/tools/parsers/pythonic.js +267 -0
- package/dist/server/utils/tools/shared.d.ts +18 -0
- package/dist/server/utils/tools/shared.js +54 -0
- package/dist/server/utils/worker-lock.d.ts +3 -0
- package/dist/server/utils/worker-lock.js +67 -0
- package/dist/server/worker-core.d.ts +16 -1
- package/dist/server/worker-core.js +114 -14
- package/dist/utils/aggregate-events.d.ts +16 -0
- package/dist/utils/aggregate-events.js +52 -0
- package/dist/utils/cache-normalize.d.ts +10 -0
- package/dist/utils/cache-normalize.js +23 -0
- package/dist/utils/encoding.d.ts +8 -0
- package/dist/utils/encoding.js +13 -0
- package/dist/utils/errors-client.d.ts +12 -0
- package/dist/utils/errors-client.js +20 -0
- package/dist/utils/errors-server.d.ts +14 -0
- package/dist/utils/errors-server.js +31 -0
- package/dist/utils/load-model-validation.d.ts +7 -0
- package/dist/utils/load-model-validation.js +18 -0
- package/expo/plugins/patches/android-link.mjs +1 -1
- package/expo/plugins/patches/ios-link.mjs +1 -1
- package/package.json +14 -18
- package/dist/examples/translation/translation-opus.d.ts +0 -2
- package/dist/examples/translation/translation-opus.js +0 -33
- package/dist/server/bare/utils/loader-adapter.d.ts +0 -7
- package/dist/server/bare/utils/loader-adapter.js +0 -9
- package/dist/server/utils/model-path.d.ts +0 -5
- package/dist/server/utils/model-path.js +0 -7
- package/dist/server/utils/tool-parser.d.ts +0 -7
- package/dist/server/utils/tool-parser.js +0 -248
|
@@ -4,35 +4,6 @@ export declare const nmtPlugin: {
|
|
|
4
4
|
displayName: string;
|
|
5
5
|
addonPackage: "@qvac/translation-nmtcpp";
|
|
6
6
|
loadConfigSchema: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
7
|
-
mode: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
8
|
-
full: "full";
|
|
9
|
-
}>>;
|
|
10
|
-
beamsize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
11
|
-
lengthpenalty: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
12
|
-
maxlength: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
13
|
-
repetitionpenalty: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
14
|
-
norepeatngramsize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
15
|
-
temperature: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
16
|
-
topk: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
17
|
-
topp: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
18
|
-
engine: import("zod").ZodLiteral<"Opus">;
|
|
19
|
-
from: import("zod").ZodEnum<{
|
|
20
|
-
en: "en";
|
|
21
|
-
de: "de";
|
|
22
|
-
es: "es";
|
|
23
|
-
it: "it";
|
|
24
|
-
ru: "ru";
|
|
25
|
-
ja: "ja";
|
|
26
|
-
}>;
|
|
27
|
-
to: import("zod").ZodEnum<{
|
|
28
|
-
en: "en";
|
|
29
|
-
de: "de";
|
|
30
|
-
es: "es";
|
|
31
|
-
it: "it";
|
|
32
|
-
ru: "ru";
|
|
33
|
-
ja: "ja";
|
|
34
|
-
}>;
|
|
35
|
-
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
36
7
|
mode: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
37
8
|
full: "full";
|
|
38
9
|
}>>;
|
|
@@ -46,58 +17,112 @@ export declare const nmtPlugin: {
|
|
|
46
17
|
topp: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
47
18
|
engine: import("zod").ZodLiteral<"Bergamot">;
|
|
48
19
|
from: import("zod").ZodEnum<{
|
|
20
|
+
id: "id";
|
|
49
21
|
en: "en";
|
|
50
|
-
de: "de";
|
|
51
|
-
es: "es";
|
|
52
|
-
it: "it";
|
|
53
|
-
ru: "ru";
|
|
54
|
-
ja: "ja";
|
|
55
22
|
ar: "ar";
|
|
56
23
|
bg: "bg";
|
|
57
24
|
ca: "ca";
|
|
58
25
|
cs: "cs";
|
|
26
|
+
de: "de";
|
|
27
|
+
es: "es";
|
|
59
28
|
et: "et";
|
|
60
29
|
fi: "fi";
|
|
61
30
|
fr: "fr";
|
|
62
31
|
hu: "hu";
|
|
63
32
|
is: "is";
|
|
33
|
+
it: "it";
|
|
34
|
+
ja: "ja";
|
|
64
35
|
ko: "ko";
|
|
65
36
|
lt: "lt";
|
|
66
37
|
lv: "lv";
|
|
67
38
|
nl: "nl";
|
|
68
39
|
pl: "pl";
|
|
69
40
|
pt: "pt";
|
|
41
|
+
ru: "ru";
|
|
70
42
|
sk: "sk";
|
|
71
43
|
sl: "sl";
|
|
72
44
|
uk: "uk";
|
|
73
45
|
zh: "zh";
|
|
46
|
+
az: "az";
|
|
47
|
+
be: "be";
|
|
48
|
+
bn: "bn";
|
|
49
|
+
bs: "bs";
|
|
50
|
+
da: "da";
|
|
51
|
+
el: "el";
|
|
52
|
+
fa: "fa";
|
|
53
|
+
gu: "gu";
|
|
54
|
+
he: "he";
|
|
55
|
+
hi: "hi";
|
|
56
|
+
hr: "hr";
|
|
57
|
+
kn: "kn";
|
|
58
|
+
ml: "ml";
|
|
59
|
+
ms: "ms";
|
|
60
|
+
mt: "mt";
|
|
61
|
+
nb: "nb";
|
|
62
|
+
nn: "nn";
|
|
63
|
+
re: "re";
|
|
64
|
+
ro: "ro";
|
|
65
|
+
sq: "sq";
|
|
66
|
+
sr: "sr";
|
|
67
|
+
sv: "sv";
|
|
68
|
+
ta: "ta";
|
|
69
|
+
te: "te";
|
|
70
|
+
tr: "tr";
|
|
71
|
+
vi: "vi";
|
|
74
72
|
}>;
|
|
75
73
|
to: import("zod").ZodEnum<{
|
|
74
|
+
id: "id";
|
|
76
75
|
en: "en";
|
|
77
|
-
de: "de";
|
|
78
|
-
es: "es";
|
|
79
|
-
it: "it";
|
|
80
|
-
ru: "ru";
|
|
81
|
-
ja: "ja";
|
|
82
76
|
ar: "ar";
|
|
83
77
|
bg: "bg";
|
|
84
78
|
ca: "ca";
|
|
85
79
|
cs: "cs";
|
|
80
|
+
de: "de";
|
|
81
|
+
es: "es";
|
|
86
82
|
et: "et";
|
|
87
83
|
fi: "fi";
|
|
88
84
|
fr: "fr";
|
|
89
85
|
hu: "hu";
|
|
90
86
|
is: "is";
|
|
87
|
+
it: "it";
|
|
88
|
+
ja: "ja";
|
|
91
89
|
ko: "ko";
|
|
92
90
|
lt: "lt";
|
|
93
91
|
lv: "lv";
|
|
94
92
|
nl: "nl";
|
|
95
93
|
pl: "pl";
|
|
96
94
|
pt: "pt";
|
|
95
|
+
ru: "ru";
|
|
97
96
|
sk: "sk";
|
|
98
97
|
sl: "sl";
|
|
99
98
|
uk: "uk";
|
|
100
99
|
zh: "zh";
|
|
100
|
+
az: "az";
|
|
101
|
+
be: "be";
|
|
102
|
+
bn: "bn";
|
|
103
|
+
bs: "bs";
|
|
104
|
+
da: "da";
|
|
105
|
+
el: "el";
|
|
106
|
+
fa: "fa";
|
|
107
|
+
gu: "gu";
|
|
108
|
+
he: "he";
|
|
109
|
+
hi: "hi";
|
|
110
|
+
hr: "hr";
|
|
111
|
+
kn: "kn";
|
|
112
|
+
ml: "ml";
|
|
113
|
+
ms: "ms";
|
|
114
|
+
mt: "mt";
|
|
115
|
+
nb: "nb";
|
|
116
|
+
nn: "nn";
|
|
117
|
+
re: "re";
|
|
118
|
+
ro: "ro";
|
|
119
|
+
sq: "sq";
|
|
120
|
+
sr: "sr";
|
|
121
|
+
sv: "sv";
|
|
122
|
+
ta: "ta";
|
|
123
|
+
te: "te";
|
|
124
|
+
tr: "tr";
|
|
125
|
+
vi: "vi";
|
|
101
126
|
}>;
|
|
102
127
|
srcVocabSrc: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodObject<{
|
|
103
128
|
src: import("zod").ZodString;
|
|
@@ -111,6 +136,7 @@ export declare const nmtPlugin: {
|
|
|
111
136
|
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
112
137
|
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
113
138
|
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
139
|
+
embeddings: "embeddings";
|
|
114
140
|
"llamacpp-completion": "llamacpp-completion";
|
|
115
141
|
"whispercpp-transcription": "whispercpp-transcription";
|
|
116
142
|
"llamacpp-embedding": "llamacpp-embedding";
|
|
@@ -121,7 +147,6 @@ export declare const nmtPlugin: {
|
|
|
121
147
|
"sdcpp-generation": "sdcpp-generation";
|
|
122
148
|
llm: "llm";
|
|
123
149
|
whisper: "whisper";
|
|
124
|
-
embeddings: "embeddings";
|
|
125
150
|
nmt: "nmt";
|
|
126
151
|
parakeet: "parakeet";
|
|
127
152
|
tts: "tts";
|
|
@@ -141,6 +166,7 @@ export declare const nmtPlugin: {
|
|
|
141
166
|
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
142
167
|
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
143
168
|
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
169
|
+
embeddings: "embeddings";
|
|
144
170
|
"llamacpp-completion": "llamacpp-completion";
|
|
145
171
|
"whispercpp-transcription": "whispercpp-transcription";
|
|
146
172
|
"llamacpp-embedding": "llamacpp-embedding";
|
|
@@ -151,7 +177,6 @@ export declare const nmtPlugin: {
|
|
|
151
177
|
"sdcpp-generation": "sdcpp-generation";
|
|
152
178
|
llm: "llm";
|
|
153
179
|
whisper: "whisper";
|
|
154
|
-
embeddings: "embeddings";
|
|
155
180
|
nmt: "nmt";
|
|
156
181
|
parakeet: "parakeet";
|
|
157
182
|
tts: "tts";
|
|
@@ -184,6 +209,7 @@ export declare const nmtPlugin: {
|
|
|
184
209
|
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
185
210
|
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
186
211
|
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
212
|
+
embeddings: "embeddings";
|
|
187
213
|
"llamacpp-completion": "llamacpp-completion";
|
|
188
214
|
"whispercpp-transcription": "whispercpp-transcription";
|
|
189
215
|
"llamacpp-embedding": "llamacpp-embedding";
|
|
@@ -194,7 +220,6 @@ export declare const nmtPlugin: {
|
|
|
194
220
|
"sdcpp-generation": "sdcpp-generation";
|
|
195
221
|
llm: "llm";
|
|
196
222
|
whisper: "whisper";
|
|
197
|
-
embeddings: "embeddings";
|
|
198
223
|
nmt: "nmt";
|
|
199
224
|
parakeet: "parakeet";
|
|
200
225
|
tts: "tts";
|
|
@@ -214,6 +239,7 @@ export declare const nmtPlugin: {
|
|
|
214
239
|
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
215
240
|
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
216
241
|
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
242
|
+
embeddings: "embeddings";
|
|
217
243
|
"llamacpp-completion": "llamacpp-completion";
|
|
218
244
|
"whispercpp-transcription": "whispercpp-transcription";
|
|
219
245
|
"llamacpp-embedding": "llamacpp-embedding";
|
|
@@ -224,7 +250,6 @@ export declare const nmtPlugin: {
|
|
|
224
250
|
"sdcpp-generation": "sdcpp-generation";
|
|
225
251
|
llm: "llm";
|
|
226
252
|
whisper: "whisper";
|
|
227
|
-
embeddings: "embeddings";
|
|
228
253
|
nmt: "nmt";
|
|
229
254
|
parakeet: "parakeet";
|
|
230
255
|
tts: "tts";
|
|
@@ -244,6 +269,7 @@ export declare const nmtPlugin: {
|
|
|
244
269
|
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
245
270
|
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
246
271
|
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
272
|
+
embeddings: "embeddings";
|
|
247
273
|
"llamacpp-completion": "llamacpp-completion";
|
|
248
274
|
"whispercpp-transcription": "whispercpp-transcription";
|
|
249
275
|
"llamacpp-embedding": "llamacpp-embedding";
|
|
@@ -254,7 +280,6 @@ export declare const nmtPlugin: {
|
|
|
254
280
|
"sdcpp-generation": "sdcpp-generation";
|
|
255
281
|
llm: "llm";
|
|
256
282
|
whisper: "whisper";
|
|
257
|
-
embeddings: "embeddings";
|
|
258
283
|
nmt: "nmt";
|
|
259
284
|
parakeet: "parakeet";
|
|
260
285
|
tts: "tts";
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import nmtAddonLogging from "@qvac/translation-nmtcpp/addonLogging.js";
|
|
2
2
|
import TranslationNmtcpp, {} from "@qvac/translation-nmtcpp";
|
|
3
|
-
import { definePlugin, defineHandler, translateRequestSchema, translateResponseSchema, ModelType, nmtConfigBaseSchema, ADDON_NMT, } from "../../../../schemas/index.js";
|
|
3
|
+
import { definePlugin, defineHandler, translateRequestSchema, translateResponseSchema, ModelType, nmtConfigBaseSchema, ADDON_NMT, BERGAMOT_CJK_LANG_PAIRS, } from "../../../../schemas/index.js";
|
|
4
4
|
import { createStreamLogger, registerAddonLogger } from "../../../../logging/index.js";
|
|
5
|
-
import
|
|
6
|
-
import FilesystemDL from "@qvac/dl-filesystem";
|
|
5
|
+
import path from "bare-path";
|
|
7
6
|
import { ModelLoadFailedError } from "../../../../utils/errors-server.js";
|
|
8
|
-
import { asLoader } from "../../utils/loader-adapter.js";
|
|
9
7
|
import { translate } from "../../ops/translate.js";
|
|
10
8
|
import { attachModelExecutionMs } from "../../../../profiling/model-execution.js";
|
|
11
|
-
const BERGAMOT_CJK_LANG_PAIRS = ["enja", "enko", "enzh"];
|
|
12
9
|
function buildBergamotVocabSources(basePath, langPair) {
|
|
13
10
|
if (BERGAMOT_CJK_LANG_PAIRS.includes(langPair)) {
|
|
14
11
|
return {
|
|
@@ -35,23 +32,39 @@ function deriveBergamotRegistryVocabSources(modelSrc) {
|
|
|
35
32
|
const langPair = match[2];
|
|
36
33
|
return buildBergamotVocabSources(basePath, langPair);
|
|
37
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Derive absolute vocab paths from a resolved Bergamot model path.
|
|
37
|
+
* Works for both companion-set layout (colocated files) and any layout where
|
|
38
|
+
* vocab follows the standard naming convention beside the model binary.
|
|
39
|
+
* Returns null if modelPath is not a recognisable Bergamot model.
|
|
40
|
+
*/
|
|
41
|
+
function deriveColocatedBergamotVocabPaths(modelPath) {
|
|
42
|
+
const dirPath = path.dirname(modelPath);
|
|
43
|
+
const basePath = path.basename(modelPath);
|
|
44
|
+
const match = basePath.match(/^model\.([a-z]+)\.intgemm\.alphas\.bin$/);
|
|
45
|
+
if (!match?.[1])
|
|
46
|
+
return null;
|
|
47
|
+
const langPair = match[1];
|
|
48
|
+
if (BERGAMOT_CJK_LANG_PAIRS.includes(langPair)) {
|
|
49
|
+
return {
|
|
50
|
+
srcVocabPath: path.join(dirPath, `srcvocab.${langPair}.spm`),
|
|
51
|
+
dstVocabPath: path.join(dirPath, `trgvocab.${langPair}.spm`),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const sharedPath = path.join(dirPath, `vocab.${langPair}.spm`);
|
|
55
|
+
return { srcVocabPath: sharedPath, dstVocabPath: sharedPath };
|
|
56
|
+
}
|
|
38
57
|
function createNmtModel(modelId, modelPath, nmtConfig, srcVocabPath, dstVocabPath, pivotModelPath, pivotSrcVocabPath, pivotDstVocabPath) {
|
|
39
|
-
const { dirPath, basePath } = parseModelPath(modelPath);
|
|
40
|
-
const loader = new FilesystemDL({ dirPath });
|
|
41
58
|
const logger = createStreamLogger(modelId, ModelType.nmtcppTranslation);
|
|
42
59
|
registerAddonLogger(modelId, ModelType.nmtcppTranslation, logger);
|
|
43
60
|
const { mode, from, to, engine, beamsize, lengthpenalty, maxlength, repetitionpenalty, norepeatngramsize, temperature, topk, topp, } = nmtConfig;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
mode,
|
|
52
|
-
srcLang: from,
|
|
53
|
-
dstLang: to,
|
|
54
|
-
},
|
|
61
|
+
const files = {
|
|
62
|
+
model: modelPath,
|
|
63
|
+
...(srcVocabPath && { srcVocab: srcVocabPath }),
|
|
64
|
+
...(dstVocabPath && { dstVocab: dstVocabPath }),
|
|
65
|
+
...(pivotModelPath && { pivotModel: pivotModelPath }),
|
|
66
|
+
...(pivotSrcVocabPath && { pivotSrcVocab: pivotSrcVocabPath }),
|
|
67
|
+
...(pivotDstVocabPath && { pivotDstVocab: pivotDstVocabPath }),
|
|
55
68
|
};
|
|
56
69
|
const generationParams = {
|
|
57
70
|
beamsize,
|
|
@@ -67,33 +80,81 @@ function createNmtModel(modelId, modelPath, nmtConfig, srcVocabPath, dstVocabPat
|
|
|
67
80
|
modelType: TranslationNmtcpp.ModelTypes[engine],
|
|
68
81
|
...generationParams,
|
|
69
82
|
...(nmtConfig.engine === "Bergamot" && {
|
|
70
|
-
...(srcVocabPath && { srcVocabPath }),
|
|
71
|
-
...(dstVocabPath && { dstVocabPath }),
|
|
72
83
|
...(nmtConfig.normalize !== undefined && {
|
|
73
84
|
normalize: nmtConfig.normalize,
|
|
74
85
|
}),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
bergamotPivotModel: (() => {
|
|
86
|
+
...(nmtConfig.pivotModel && pivotModelPath && {
|
|
87
|
+
pivotConfig: (() => {
|
|
78
88
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
|
-
const { modelSrc, dstVocabSrc, srcVocabSrc, ...
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
loader: asLoader(new FilesystemDL({ dirPath })),
|
|
83
|
-
modelName: basePath,
|
|
84
|
-
diskPath: dirPath,
|
|
85
|
-
config: {
|
|
86
|
-
...config,
|
|
87
|
-
srcVocabPath: pivotSrcVocabPath,
|
|
88
|
-
dstVocabPath: pivotDstVocabPath
|
|
89
|
-
}
|
|
90
|
-
};
|
|
89
|
+
const { modelSrc, dstVocabSrc, srcVocabSrc, ...pivotGenConfig } = nmtConfig.pivotModel;
|
|
90
|
+
return pivotGenConfig;
|
|
91
91
|
})(),
|
|
92
92
|
}),
|
|
93
93
|
}),
|
|
94
94
|
};
|
|
95
|
-
const model = new TranslationNmtcpp(
|
|
96
|
-
|
|
95
|
+
const model = new TranslationNmtcpp({
|
|
96
|
+
files,
|
|
97
|
+
params: { mode, srcLang: from, dstLang: to },
|
|
98
|
+
config,
|
|
99
|
+
logger,
|
|
100
|
+
opts: { stats: true },
|
|
101
|
+
});
|
|
102
|
+
return { model };
|
|
103
|
+
}
|
|
104
|
+
async function resolveBergamotVocab(nmtConfig, ctx, srcVocabSrc, dstVocabSrc, pivotModel) {
|
|
105
|
+
let srcSrc = srcVocabSrc;
|
|
106
|
+
let dstSrc = dstVocabSrc;
|
|
107
|
+
if (!srcSrc || !dstSrc) {
|
|
108
|
+
const derived = ctx.modelSrc.startsWith("pear://")
|
|
109
|
+
? deriveBergamotVocabSources(ctx.modelSrc)
|
|
110
|
+
: ctx.modelSrc.startsWith("registry://")
|
|
111
|
+
? deriveBergamotRegistryVocabSources(ctx.modelSrc)
|
|
112
|
+
: null;
|
|
113
|
+
if (derived) {
|
|
114
|
+
srcSrc = srcSrc ?? derived.srcVocabSrc;
|
|
115
|
+
dstSrc = dstSrc ?? derived.dstVocabSrc;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!srcSrc || !dstSrc) {
|
|
119
|
+
throw new ModelLoadFailedError("Bergamot requires srcVocabSrc and dstVocabSrc. Provide them in modelConfig or use a pear:// or registry:// model source for auto-derivation.");
|
|
120
|
+
}
|
|
121
|
+
if (!pivotModel) {
|
|
122
|
+
const [srcVocabPath, dstVocabPath] = await Promise.all([
|
|
123
|
+
ctx.resolveModelPath(srcSrc),
|
|
124
|
+
ctx.resolveModelPath(dstSrc),
|
|
125
|
+
]);
|
|
126
|
+
return {
|
|
127
|
+
config: nmtConfig,
|
|
128
|
+
artifacts: { srcVocabPath, dstVocabPath },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
let pivotSrcSrc = pivotModel.srcVocabSrc;
|
|
132
|
+
let pivotDstSrc = pivotModel.dstVocabSrc;
|
|
133
|
+
if (!pivotSrcSrc || !pivotDstSrc) {
|
|
134
|
+
const pivotDerived = pivotModel.modelSrc.startsWith("pear://")
|
|
135
|
+
? deriveBergamotVocabSources(pivotModel.modelSrc)
|
|
136
|
+
: pivotModel.modelSrc.startsWith("registry://")
|
|
137
|
+
? deriveBergamotRegistryVocabSources(pivotModel.modelSrc)
|
|
138
|
+
: null;
|
|
139
|
+
if (pivotDerived) {
|
|
140
|
+
pivotSrcSrc = pivotSrcSrc ?? pivotDerived.srcVocabSrc;
|
|
141
|
+
pivotDstSrc = pivotDstSrc ?? pivotDerived.dstVocabSrc;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!pivotSrcSrc || !pivotDstSrc) {
|
|
145
|
+
throw new ModelLoadFailedError("Bergamot pivot model requires srcVocabSrc and dstVocabSrc. Provide them in modelConfig or use a pear:// or registry:// model source for auto-derivation.");
|
|
146
|
+
}
|
|
147
|
+
const [srcVocabPath, dstVocabPath, pivotSrcVocabPath, pivotDstVocabPath, pivotModelPath] = await Promise.all([
|
|
148
|
+
ctx.resolveModelPath(srcSrc),
|
|
149
|
+
ctx.resolveModelPath(dstSrc),
|
|
150
|
+
ctx.resolveModelPath(pivotSrcSrc),
|
|
151
|
+
ctx.resolveModelPath(pivotDstSrc),
|
|
152
|
+
ctx.resolveModelPath(pivotModel.modelSrc),
|
|
153
|
+
]);
|
|
154
|
+
return {
|
|
155
|
+
config: nmtConfig,
|
|
156
|
+
artifacts: { srcVocabPath, dstVocabPath, pivotSrcVocabPath, pivotDstVocabPath, pivotModelPath },
|
|
157
|
+
};
|
|
97
158
|
}
|
|
98
159
|
export const nmtPlugin = definePlugin({
|
|
99
160
|
modelType: ModelType.nmtcppTranslation,
|
|
@@ -101,69 +162,27 @@ export const nmtPlugin = definePlugin({
|
|
|
101
162
|
addonPackage: ADDON_NMT,
|
|
102
163
|
loadConfigSchema: nmtConfigBaseSchema,
|
|
103
164
|
async resolveConfig(cfg, ctx) {
|
|
104
|
-
const { srcVocabSrc, dstVocabSrc, ...nmtConfig } = cfg;
|
|
165
|
+
const { srcVocabSrc, dstVocabSrc, pivotModel, ...nmtConfig } = cfg;
|
|
105
166
|
if (nmtConfig.engine !== "Bergamot") {
|
|
106
167
|
return { config: nmtConfig };
|
|
107
168
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!srcSrc || !dstSrc) {
|
|
111
|
-
const derived = ctx.modelSrc.startsWith("pear://")
|
|
112
|
-
? deriveBergamotVocabSources(ctx.modelSrc)
|
|
113
|
-
: ctx.modelSrc.startsWith("registry://")
|
|
114
|
-
? deriveBergamotRegistryVocabSources(ctx.modelSrc)
|
|
115
|
-
: null;
|
|
116
|
-
if (derived) {
|
|
117
|
-
srcSrc = srcSrc ?? derived.srcVocabSrc;
|
|
118
|
-
dstSrc = dstSrc ?? derived.dstVocabSrc;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (!srcSrc || !dstSrc) {
|
|
122
|
-
throw new ModelLoadFailedError("Bergamot requires srcVocabSrc and dstVocabSrc. Provide them in modelConfig or use a pear:// or registry:// model source for auto-derivation.");
|
|
123
|
-
}
|
|
124
|
-
const pivotModel = nmtConfig.pivotModel;
|
|
125
|
-
if (!pivotModel) {
|
|
126
|
-
const [srcVocabPath, dstVocabPath] = await Promise.all([
|
|
127
|
-
ctx.resolveModelPath(srcSrc),
|
|
128
|
-
ctx.resolveModelPath(dstSrc),
|
|
129
|
-
]);
|
|
130
|
-
return {
|
|
131
|
-
config: nmtConfig,
|
|
132
|
-
artifacts: { srcVocabPath, dstVocabPath },
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
let pivotSrcSrc = pivotModel.srcVocabSrc;
|
|
136
|
-
let pivotDstSrc = pivotModel.dstVocabSrc;
|
|
137
|
-
if (!pivotSrcSrc || !pivotDstSrc) {
|
|
138
|
-
const pivotDerived = pivotModel.modelSrc.startsWith("pear://")
|
|
139
|
-
? deriveBergamotVocabSources(pivotModel.modelSrc)
|
|
140
|
-
: pivotModel.modelSrc.startsWith("registry://")
|
|
141
|
-
? deriveBergamotRegistryVocabSources(pivotModel.modelSrc)
|
|
142
|
-
: null;
|
|
143
|
-
if (pivotDerived) {
|
|
144
|
-
pivotSrcSrc = pivotSrcSrc ?? pivotDerived.srcVocabSrc;
|
|
145
|
-
pivotDstSrc = pivotDstSrc ?? pivotDerived.dstVocabSrc;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (!pivotSrcSrc || !pivotDstSrc) {
|
|
149
|
-
throw new ModelLoadFailedError("Bergamot pivot model requires srcVocabSrc and dstVocabSrc. Provide them in modelConfig or use a pear:// or registry:// model source for auto-derivation.");
|
|
150
|
-
}
|
|
151
|
-
const [srcVocabPath, dstVocabPath, pivotSrcVocabPath, pivotDstVocabPath, pivotModelPath] = await Promise.all([
|
|
152
|
-
ctx.resolveModelPath(srcSrc),
|
|
153
|
-
ctx.resolveModelPath(dstSrc),
|
|
154
|
-
ctx.resolveModelPath(pivotSrcSrc),
|
|
155
|
-
ctx.resolveModelPath(pivotDstSrc),
|
|
156
|
-
ctx.resolveModelPath(pivotModel.modelSrc),
|
|
157
|
-
]);
|
|
158
|
-
return {
|
|
159
|
-
config: nmtConfig,
|
|
160
|
-
artifacts: { srcVocabPath, dstVocabPath, pivotSrcVocabPath, pivotDstVocabPath, pivotModelPath },
|
|
161
|
-
};
|
|
169
|
+
const bergamotConfig = { ...nmtConfig, ...(pivotModel && { pivotModel }) };
|
|
170
|
+
return resolveBergamotVocab(bergamotConfig, ctx, srcVocabSrc, dstVocabSrc, pivotModel);
|
|
162
171
|
},
|
|
163
172
|
createModel(params) {
|
|
164
173
|
const nmtConfig = (params.modelConfig ?? {});
|
|
165
|
-
const
|
|
166
|
-
|
|
174
|
+
const artifacts = params.artifacts ?? {};
|
|
175
|
+
const derived = deriveColocatedBergamotVocabPaths(params.modelPath);
|
|
176
|
+
const srcVocabPath = artifacts["srcVocabPath"] ?? derived?.srcVocabPath;
|
|
177
|
+
const dstVocabPath = artifacts["dstVocabPath"] ?? derived?.dstVocabPath;
|
|
178
|
+
const pivotModelPath = artifacts["pivotModelPath"];
|
|
179
|
+
const pivotDerived = pivotModelPath
|
|
180
|
+
? deriveColocatedBergamotVocabPaths(pivotModelPath)
|
|
181
|
+
: null;
|
|
182
|
+
const pivotSrcVocabPath = artifacts["pivotSrcVocabPath"] ?? pivotDerived?.srcVocabPath;
|
|
183
|
+
const pivotDstVocabPath = artifacts["pivotDstVocabPath"] ?? pivotDerived?.dstVocabPath;
|
|
184
|
+
const { model } = createNmtModel(params.modelId, params.modelPath, nmtConfig, srcVocabPath, dstVocabPath, pivotModelPath, pivotSrcVocabPath, pivotDstVocabPath);
|
|
185
|
+
return { model };
|
|
167
186
|
},
|
|
168
187
|
handlers: {
|
|
169
188
|
translate: defineHandler({
|
|
@@ -33,6 +33,7 @@ export declare const ocrPlugin: {
|
|
|
33
33
|
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
34
34
|
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
35
35
|
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
36
|
+
embeddings: "embeddings";
|
|
36
37
|
"llamacpp-completion": "llamacpp-completion";
|
|
37
38
|
"whispercpp-transcription": "whispercpp-transcription";
|
|
38
39
|
"llamacpp-embedding": "llamacpp-embedding";
|
|
@@ -43,7 +44,6 @@ export declare const ocrPlugin: {
|
|
|
43
44
|
"sdcpp-generation": "sdcpp-generation";
|
|
44
45
|
llm: "llm";
|
|
45
46
|
whisper: "whisper";
|
|
46
|
-
embeddings: "embeddings";
|
|
47
47
|
nmt: "nmt";
|
|
48
48
|
parakeet: "parakeet";
|
|
49
49
|
tts: "tts";
|
|
@@ -54,7 +54,6 @@ function createOCRModel(modelId, detectorPath, recognizerPath, ocrConfig) {
|
|
|
54
54
|
params,
|
|
55
55
|
opts: { stats: true },
|
|
56
56
|
};
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
58
57
|
const model = new ONNXOcr(args);
|
|
59
58
|
return model;
|
|
60
59
|
}
|
|
@@ -83,7 +82,7 @@ export const ocrPlugin = definePlugin({
|
|
|
83
82
|
}
|
|
84
83
|
const model = createOCRModel(params.modelId, detectorModelPath, params.modelPath, // recognizerPath
|
|
85
84
|
ocrConfig);
|
|
86
|
-
return { model
|
|
85
|
+
return { model };
|
|
87
86
|
},
|
|
88
87
|
handlers: {
|
|
89
88
|
ocrStream: defineHandler({
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TextToSpeechStreamRequest, type TtsStats } from "../../../../../schemas/index";
|
|
2
|
+
import { type TtsOpYield } from "../../../utils/tts-stats";
|
|
3
|
+
export declare function textToSpeechStream(params: TextToSpeechStreamRequest, inputStream: AsyncIterable<Buffer>): AsyncGenerator<TtsOpYield, {
|
|
4
|
+
modelExecutionMs: number;
|
|
5
|
+
stats?: TtsStats;
|
|
6
|
+
}, unknown>;
|
|
7
|
+
//# sourceMappingURL=text-to-speech-stream.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { getModel } from "../../../registry/model-registry.js";
|
|
2
|
+
import { textToSpeechStreamRequestSchema, } from "../../../../../schemas/index.js";
|
|
3
|
+
import { nowMs } from "../../../../../profiling/index.js";
|
|
4
|
+
import { buildStreamResult, hasDefinedValues } from "../../../../../profiling/model-execution.js";
|
|
5
|
+
import { TextToSpeechStreamFailedError } from "../../../../../utils/errors-server.js";
|
|
6
|
+
import { collectTtsStats, } from "../../../utils/tts-stats.js";
|
|
7
|
+
function hasRunStreaming(model) {
|
|
8
|
+
return (typeof model === "object" &&
|
|
9
|
+
model !== null &&
|
|
10
|
+
"runStreaming" in model &&
|
|
11
|
+
typeof model.runStreaming === "function");
|
|
12
|
+
}
|
|
13
|
+
// Callers (e.g. LLM token deltas) may write raw Buffer chunks whose
|
|
14
|
+
// boundaries split a multi-byte UTF-8 codepoint. A naive `buf.toString("utf8")`
|
|
15
|
+
// per chunk emits U+FFFD at every split point and silently corrupts CJK,
|
|
16
|
+
// emoji, accented scripts, etc. before they reach the tokenizer. Keep a
|
|
17
|
+
// tail-buffer of at most 3 bytes spanning an incomplete trailing codepoint
|
|
18
|
+
// and decode only the complete-codepoint prefix of each combined chunk.
|
|
19
|
+
function findLastCompleteUtf8End(buf) {
|
|
20
|
+
const len = buf.length;
|
|
21
|
+
// A UTF-8 codepoint is at most 4 bytes, so a split can only dangle in
|
|
22
|
+
// the last 3 bytes. Scan backwards to find the most recent leading byte.
|
|
23
|
+
for (let i = len - 1; i >= 0 && i >= len - 3; i--) {
|
|
24
|
+
const b = buf[i];
|
|
25
|
+
if ((b & 0x80) === 0) {
|
|
26
|
+
// ASCII byte: everything up to and including i is complete.
|
|
27
|
+
return i + 1;
|
|
28
|
+
}
|
|
29
|
+
if ((b & 0xc0) === 0xc0) {
|
|
30
|
+
// Leading byte of a multi-byte sequence.
|
|
31
|
+
let expected;
|
|
32
|
+
if ((b & 0xe0) === 0xc0)
|
|
33
|
+
expected = 2;
|
|
34
|
+
else if ((b & 0xf0) === 0xe0)
|
|
35
|
+
expected = 3;
|
|
36
|
+
else if ((b & 0xf8) === 0xf0)
|
|
37
|
+
expected = 4;
|
|
38
|
+
else
|
|
39
|
+
return len; // Invalid leader; let toString emit U+FFFD.
|
|
40
|
+
return i + expected <= len ? len : i;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return len;
|
|
44
|
+
}
|
|
45
|
+
async function* buffersToUtf8Fragments(inputStream) {
|
|
46
|
+
let pending = Buffer.alloc(0);
|
|
47
|
+
for await (const buf of inputStream) {
|
|
48
|
+
const combined = pending.length === 0 ? buf : Buffer.concat([pending, buf]);
|
|
49
|
+
const completeEnd = findLastCompleteUtf8End(combined);
|
|
50
|
+
if (completeEnd > 0) {
|
|
51
|
+
const s = combined.subarray(0, completeEnd).toString("utf8");
|
|
52
|
+
if (s.length > 0) {
|
|
53
|
+
yield s;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
pending =
|
|
57
|
+
completeEnd < combined.length
|
|
58
|
+
? Buffer.from(combined.subarray(completeEnd))
|
|
59
|
+
: Buffer.alloc(0);
|
|
60
|
+
}
|
|
61
|
+
if (pending.length > 0) {
|
|
62
|
+
// Stream ended with a dangling partial codepoint — flush as-is so the
|
|
63
|
+
// tokenizer sees the replacement character rather than silently dropping
|
|
64
|
+
// the final byte(s).
|
|
65
|
+
const s = pending.toString("utf8");
|
|
66
|
+
if (s.length > 0) {
|
|
67
|
+
yield s;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function buildRunStreamingOptions(request) {
|
|
72
|
+
const o = {};
|
|
73
|
+
if (request.accumulateSentences !== undefined) {
|
|
74
|
+
o["accumulateSentences"] = request.accumulateSentences;
|
|
75
|
+
}
|
|
76
|
+
if (request.sentenceDelimiterPreset !== undefined) {
|
|
77
|
+
o["sentenceDelimiterPreset"] = request.sentenceDelimiterPreset;
|
|
78
|
+
}
|
|
79
|
+
if (request.maxBufferScalars !== undefined) {
|
|
80
|
+
o["maxBufferScalars"] = request.maxBufferScalars;
|
|
81
|
+
}
|
|
82
|
+
if (request.flushAfterMs !== undefined) {
|
|
83
|
+
o["flushAfterMs"] = request.flushAfterMs;
|
|
84
|
+
}
|
|
85
|
+
return o;
|
|
86
|
+
}
|
|
87
|
+
export async function* textToSpeechStream(params, inputStream) {
|
|
88
|
+
const request = textToSpeechStreamRequestSchema.parse(params);
|
|
89
|
+
const model = getModel(request.modelId);
|
|
90
|
+
const modelStart = nowMs();
|
|
91
|
+
if (!hasRunStreaming(model)) {
|
|
92
|
+
throw new TextToSpeechStreamFailedError("textToSpeechStream requires an ONNX TTS model with runStreaming");
|
|
93
|
+
}
|
|
94
|
+
const textSource = buffersToUtf8Fragments(inputStream);
|
|
95
|
+
const streamOpts = buildRunStreamingOptions(request);
|
|
96
|
+
const response = await model.runStreaming(textSource, Object.keys(streamOpts).length > 0 ? streamOpts : undefined);
|
|
97
|
+
for await (const data of response.iterate()) {
|
|
98
|
+
if (data.outputArray == null) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const buf = Array.from(data.outputArray);
|
|
102
|
+
if (buf.length === 0) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
yield {
|
|
106
|
+
buffer: buf,
|
|
107
|
+
...(data.chunkIndex !== undefined ? { chunkIndex: data.chunkIndex } : {}),
|
|
108
|
+
...(typeof data.sentenceChunk === "string" && data.sentenceChunk.length > 0
|
|
109
|
+
? { sentenceChunk: data.sentenceChunk }
|
|
110
|
+
: {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const modelExecutionMs = nowMs() - modelStart;
|
|
114
|
+
const stats = collectTtsStats(response);
|
|
115
|
+
return buildStreamResult(modelExecutionMs, hasDefinedValues(stats) ? stats : undefined);
|
|
116
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type TtsRequest, type TtsStats } from "../../../../../schemas/index";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}, {
|
|
2
|
+
import { type TtsOpYield } from "../../../utils/tts-stats";
|
|
3
|
+
export declare function textToSpeech(params: TtsRequest): AsyncGenerator<TtsOpYield, {
|
|
5
4
|
modelExecutionMs: number;
|
|
6
5
|
stats?: TtsStats;
|
|
7
6
|
}>;
|