rag-lite-ts 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{core → cjs/core}/model-validator.js +1 -1
- package/dist/{core → cjs/core}/vector-index.js +4 -2
- package/dist/esm/api-errors.d.ts +90 -0
- package/dist/esm/api-errors.js +320 -0
- package/dist/esm/cli/indexer.d.ts +11 -0
- package/dist/esm/cli/indexer.js +471 -0
- package/dist/esm/cli/search.d.ts +7 -0
- package/dist/esm/cli/search.js +332 -0
- package/dist/esm/cli.d.ts +3 -0
- package/dist/esm/cli.js +529 -0
- package/dist/esm/config.d.ts +51 -0
- package/dist/esm/config.js +79 -0
- package/dist/esm/core/abstract-embedder.d.ts +125 -0
- package/dist/esm/core/abstract-embedder.js +264 -0
- package/dist/esm/core/actionable-error-messages.d.ts +60 -0
- package/dist/esm/core/actionable-error-messages.js +397 -0
- package/dist/esm/core/adapters.d.ts +93 -0
- package/dist/esm/core/adapters.js +139 -0
- package/dist/esm/core/batch-processing-optimizer.d.ts +155 -0
- package/dist/esm/core/batch-processing-optimizer.js +536 -0
- package/dist/esm/core/binary-index-format.d.ts +78 -0
- package/dist/esm/core/binary-index-format.js +291 -0
- package/dist/esm/core/chunker.d.ts +119 -0
- package/dist/esm/core/chunker.js +73 -0
- package/dist/esm/core/cli-database-utils.d.ts +53 -0
- package/dist/esm/core/cli-database-utils.js +239 -0
- package/dist/esm/core/config.d.ts +102 -0
- package/dist/esm/core/config.js +247 -0
- package/dist/esm/core/content-errors.d.ts +111 -0
- package/dist/esm/core/content-errors.js +362 -0
- package/dist/esm/core/content-manager.d.ts +335 -0
- package/dist/esm/core/content-manager.js +1476 -0
- package/dist/esm/core/content-performance-optimizer.d.ts +150 -0
- package/dist/esm/core/content-performance-optimizer.js +516 -0
- package/dist/esm/core/content-resolver.d.ts +104 -0
- package/dist/esm/core/content-resolver.js +285 -0
- package/dist/esm/core/cross-modal-search.d.ts +164 -0
- package/dist/esm/core/cross-modal-search.js +342 -0
- package/dist/esm/core/database-connection-manager.d.ts +109 -0
- package/dist/esm/core/database-connection-manager.js +310 -0
- package/dist/esm/core/db.d.ts +213 -0
- package/dist/esm/core/db.js +895 -0
- package/dist/esm/core/embedder-factory.d.ts +154 -0
- package/dist/esm/core/embedder-factory.js +311 -0
- package/dist/esm/core/error-handler.d.ts +112 -0
- package/dist/esm/core/error-handler.js +239 -0
- package/dist/esm/core/index.d.ts +59 -0
- package/dist/esm/core/index.js +69 -0
- package/dist/esm/core/ingestion.d.ts +202 -0
- package/dist/esm/core/ingestion.js +901 -0
- package/dist/esm/core/interfaces.d.ts +408 -0
- package/dist/esm/core/interfaces.js +106 -0
- package/dist/esm/core/lazy-dependency-loader.d.ts +147 -0
- package/dist/esm/core/lazy-dependency-loader.js +435 -0
- package/dist/esm/core/mode-detection-service.d.ts +150 -0
- package/dist/esm/core/mode-detection-service.js +565 -0
- package/dist/esm/core/mode-model-validator.d.ts +92 -0
- package/dist/esm/core/mode-model-validator.js +203 -0
- package/dist/esm/core/model-registry.d.ts +116 -0
- package/dist/esm/core/model-registry.js +411 -0
- package/dist/esm/core/model-validator.d.ts +217 -0
- package/dist/esm/core/model-validator.js +782 -0
- package/dist/esm/core/path-manager.d.ts +47 -0
- package/dist/esm/core/path-manager.js +71 -0
- package/dist/esm/core/raglite-paths.d.ts +121 -0
- package/dist/esm/core/raglite-paths.js +145 -0
- package/dist/esm/core/reranking-config.d.ts +42 -0
- package/dist/esm/core/reranking-config.js +147 -0
- package/dist/esm/core/reranking-factory.d.ts +92 -0
- package/dist/esm/core/reranking-factory.js +410 -0
- package/dist/esm/core/reranking-strategies.d.ts +310 -0
- package/dist/esm/core/reranking-strategies.js +650 -0
- package/dist/esm/core/resource-cleanup.d.ts +163 -0
- package/dist/esm/core/resource-cleanup.js +371 -0
- package/dist/esm/core/resource-manager.d.ts +212 -0
- package/dist/esm/core/resource-manager.js +564 -0
- package/dist/esm/core/search-pipeline.d.ts +111 -0
- package/dist/esm/core/search-pipeline.js +287 -0
- package/dist/esm/core/search.d.ts +141 -0
- package/dist/esm/core/search.js +320 -0
- package/dist/esm/core/streaming-operations.d.ts +145 -0
- package/dist/esm/core/streaming-operations.js +409 -0
- package/dist/esm/core/types.d.ts +66 -0
- package/dist/esm/core/types.js +6 -0
- package/dist/esm/core/universal-embedder.d.ts +177 -0
- package/dist/esm/core/universal-embedder.js +139 -0
- package/dist/esm/core/validation-messages.d.ts +99 -0
- package/dist/esm/core/validation-messages.js +334 -0
- package/dist/esm/core/vector-index.d.ts +72 -0
- package/dist/esm/core/vector-index.js +333 -0
- package/dist/esm/dom-polyfills.d.ts +6 -0
- package/dist/esm/dom-polyfills.js +37 -0
- package/dist/esm/factories/index.d.ts +27 -0
- package/dist/esm/factories/index.js +29 -0
- package/dist/esm/factories/ingestion-factory.d.ts +200 -0
- package/dist/esm/factories/ingestion-factory.js +477 -0
- package/dist/esm/factories/search-factory.d.ts +154 -0
- package/dist/esm/factories/search-factory.js +344 -0
- package/dist/esm/file-processor.d.ts +147 -0
- package/dist/esm/file-processor.js +963 -0
- package/dist/esm/index-manager.d.ts +116 -0
- package/dist/esm/index-manager.js +598 -0
- package/dist/esm/index.d.ts +75 -0
- package/dist/esm/index.js +110 -0
- package/dist/esm/indexer.d.ts +7 -0
- package/dist/esm/indexer.js +54 -0
- package/dist/esm/ingestion.d.ts +63 -0
- package/dist/esm/ingestion.js +124 -0
- package/dist/esm/mcp-server.d.ts +46 -0
- package/dist/esm/mcp-server.js +1820 -0
- package/dist/esm/multimodal/clip-embedder.d.ts +327 -0
- package/dist/esm/multimodal/clip-embedder.js +996 -0
- package/dist/esm/multimodal/index.d.ts +6 -0
- package/dist/esm/multimodal/index.js +6 -0
- package/dist/esm/preprocess.d.ts +19 -0
- package/dist/esm/preprocess.js +203 -0
- package/dist/esm/preprocessors/index.d.ts +17 -0
- package/dist/esm/preprocessors/index.js +38 -0
- package/dist/esm/preprocessors/mdx.d.ts +25 -0
- package/dist/esm/preprocessors/mdx.js +101 -0
- package/dist/esm/preprocessors/mermaid.d.ts +68 -0
- package/dist/esm/preprocessors/mermaid.js +329 -0
- package/dist/esm/preprocessors/registry.d.ts +56 -0
- package/dist/esm/preprocessors/registry.js +179 -0
- package/dist/esm/run-error-recovery-tests.d.ts +7 -0
- package/dist/esm/run-error-recovery-tests.js +101 -0
- package/dist/esm/search-standalone.d.ts +7 -0
- package/dist/esm/search-standalone.js +117 -0
- package/dist/esm/search.d.ts +99 -0
- package/dist/esm/search.js +177 -0
- package/dist/esm/test-utils.d.ts +18 -0
- package/dist/esm/test-utils.js +27 -0
- package/dist/esm/text/chunker.d.ts +33 -0
- package/dist/esm/text/chunker.js +279 -0
- package/dist/esm/text/embedder.d.ts +111 -0
- package/dist/esm/text/embedder.js +386 -0
- package/dist/esm/text/index.d.ts +8 -0
- package/dist/esm/text/index.js +9 -0
- package/dist/esm/text/preprocessors/index.d.ts +17 -0
- package/dist/esm/text/preprocessors/index.js +38 -0
- package/dist/esm/text/preprocessors/mdx.d.ts +25 -0
- package/dist/esm/text/preprocessors/mdx.js +101 -0
- package/dist/esm/text/preprocessors/mermaid.d.ts +68 -0
- package/dist/esm/text/preprocessors/mermaid.js +330 -0
- package/dist/esm/text/preprocessors/registry.d.ts +56 -0
- package/dist/esm/text/preprocessors/registry.js +180 -0
- package/dist/esm/text/reranker.d.ts +49 -0
- package/dist/esm/text/reranker.js +274 -0
- package/dist/esm/text/sentence-transformer-embedder.d.ts +96 -0
- package/dist/esm/text/sentence-transformer-embedder.js +340 -0
- package/dist/esm/text/tokenizer.d.ts +22 -0
- package/dist/esm/text/tokenizer.js +64 -0
- package/dist/esm/types.d.ts +83 -0
- package/dist/esm/types.js +3 -0
- package/dist/esm/utils/vector-math.d.ts +31 -0
- package/dist/esm/utils/vector-math.js +70 -0
- package/package.json +30 -12
- /package/dist/{api-errors.d.ts → cjs/api-errors.d.ts} +0 -0
- /package/dist/{api-errors.js → cjs/api-errors.js} +0 -0
- /package/dist/{cli → cjs/cli}/indexer.d.ts +0 -0
- /package/dist/{cli → cjs/cli}/indexer.js +0 -0
- /package/dist/{cli → cjs/cli}/search.d.ts +0 -0
- /package/dist/{cli → cjs/cli}/search.js +0 -0
- /package/dist/{cli.d.ts → cjs/cli.d.ts} +0 -0
- /package/dist/{cli.js → cjs/cli.js} +0 -0
- /package/dist/{config.d.ts → cjs/config.d.ts} +0 -0
- /package/dist/{config.js → cjs/config.js} +0 -0
- /package/dist/{core → cjs/core}/abstract-embedder.d.ts +0 -0
- /package/dist/{core → cjs/core}/abstract-embedder.js +0 -0
- /package/dist/{core → cjs/core}/actionable-error-messages.d.ts +0 -0
- /package/dist/{core → cjs/core}/actionable-error-messages.js +0 -0
- /package/dist/{core → cjs/core}/adapters.d.ts +0 -0
- /package/dist/{core → cjs/core}/adapters.js +0 -0
- /package/dist/{core → cjs/core}/batch-processing-optimizer.d.ts +0 -0
- /package/dist/{core → cjs/core}/batch-processing-optimizer.js +0 -0
- /package/dist/{core → cjs/core}/binary-index-format.d.ts +0 -0
- /package/dist/{core → cjs/core}/binary-index-format.js +0 -0
- /package/dist/{core → cjs/core}/chunker.d.ts +0 -0
- /package/dist/{core → cjs/core}/chunker.js +0 -0
- /package/dist/{core → cjs/core}/cli-database-utils.d.ts +0 -0
- /package/dist/{core → cjs/core}/cli-database-utils.js +0 -0
- /package/dist/{core → cjs/core}/config.d.ts +0 -0
- /package/dist/{core → cjs/core}/config.js +0 -0
- /package/dist/{core → cjs/core}/content-errors.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-errors.js +0 -0
- /package/dist/{core → cjs/core}/content-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-manager.js +0 -0
- /package/dist/{core → cjs/core}/content-performance-optimizer.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-performance-optimizer.js +0 -0
- /package/dist/{core → cjs/core}/content-resolver.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-resolver.js +0 -0
- /package/dist/{core → cjs/core}/cross-modal-search.d.ts +0 -0
- /package/dist/{core → cjs/core}/cross-modal-search.js +0 -0
- /package/dist/{core → cjs/core}/database-connection-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/database-connection-manager.js +0 -0
- /package/dist/{core → cjs/core}/db.d.ts +0 -0
- /package/dist/{core → cjs/core}/db.js +0 -0
- /package/dist/{core → cjs/core}/embedder-factory.d.ts +0 -0
- /package/dist/{core → cjs/core}/embedder-factory.js +0 -0
- /package/dist/{core → cjs/core}/error-handler.d.ts +0 -0
- /package/dist/{core → cjs/core}/error-handler.js +0 -0
- /package/dist/{core → cjs/core}/index.d.ts +0 -0
- /package/dist/{core → cjs/core}/index.js +0 -0
- /package/dist/{core → cjs/core}/ingestion.d.ts +0 -0
- /package/dist/{core → cjs/core}/ingestion.js +0 -0
- /package/dist/{core → cjs/core}/interfaces.d.ts +0 -0
- /package/dist/{core → cjs/core}/interfaces.js +0 -0
- /package/dist/{core → cjs/core}/lazy-dependency-loader.d.ts +0 -0
- /package/dist/{core → cjs/core}/lazy-dependency-loader.js +0 -0
- /package/dist/{core → cjs/core}/mode-detection-service.d.ts +0 -0
- /package/dist/{core → cjs/core}/mode-detection-service.js +0 -0
- /package/dist/{core → cjs/core}/mode-model-validator.d.ts +0 -0
- /package/dist/{core → cjs/core}/mode-model-validator.js +0 -0
- /package/dist/{core → cjs/core}/model-registry.d.ts +0 -0
- /package/dist/{core → cjs/core}/model-registry.js +0 -0
- /package/dist/{core → cjs/core}/model-validator.d.ts +0 -0
- /package/dist/{core → cjs/core}/path-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/path-manager.js +0 -0
- /package/dist/{core → cjs/core}/raglite-paths.d.ts +0 -0
- /package/dist/{core → cjs/core}/raglite-paths.js +0 -0
- /package/dist/{core → cjs/core}/reranking-config.d.ts +0 -0
- /package/dist/{core → cjs/core}/reranking-config.js +0 -0
- /package/dist/{core → cjs/core}/reranking-factory.d.ts +0 -0
- /package/dist/{core → cjs/core}/reranking-factory.js +0 -0
- /package/dist/{core → cjs/core}/reranking-strategies.d.ts +0 -0
- /package/dist/{core → cjs/core}/reranking-strategies.js +0 -0
- /package/dist/{core → cjs/core}/resource-cleanup.d.ts +0 -0
- /package/dist/{core → cjs/core}/resource-cleanup.js +0 -0
- /package/dist/{core → cjs/core}/resource-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/resource-manager.js +0 -0
- /package/dist/{core → cjs/core}/search-pipeline.d.ts +0 -0
- /package/dist/{core → cjs/core}/search-pipeline.js +0 -0
- /package/dist/{core → cjs/core}/search.d.ts +0 -0
- /package/dist/{core → cjs/core}/search.js +0 -0
- /package/dist/{core → cjs/core}/streaming-operations.d.ts +0 -0
- /package/dist/{core → cjs/core}/streaming-operations.js +0 -0
- /package/dist/{core → cjs/core}/types.d.ts +0 -0
- /package/dist/{core → cjs/core}/types.js +0 -0
- /package/dist/{core → cjs/core}/universal-embedder.d.ts +0 -0
- /package/dist/{core → cjs/core}/universal-embedder.js +0 -0
- /package/dist/{core → cjs/core}/validation-messages.d.ts +0 -0
- /package/dist/{core → cjs/core}/validation-messages.js +0 -0
- /package/dist/{core → cjs/core}/vector-index.d.ts +0 -0
- /package/dist/{dom-polyfills.d.ts → cjs/dom-polyfills.d.ts} +0 -0
- /package/dist/{dom-polyfills.js → cjs/dom-polyfills.js} +0 -0
- /package/dist/{factories → cjs/factories}/index.d.ts +0 -0
- /package/dist/{factories → cjs/factories}/index.js +0 -0
- /package/dist/{factories → cjs/factories}/ingestion-factory.d.ts +0 -0
- /package/dist/{factories → cjs/factories}/ingestion-factory.js +0 -0
- /package/dist/{factories → cjs/factories}/search-factory.d.ts +0 -0
- /package/dist/{factories → cjs/factories}/search-factory.js +0 -0
- /package/dist/{file-processor.d.ts → cjs/file-processor.d.ts} +0 -0
- /package/dist/{file-processor.js → cjs/file-processor.js} +0 -0
- /package/dist/{index-manager.d.ts → cjs/index-manager.d.ts} +0 -0
- /package/dist/{index-manager.js → cjs/index-manager.js} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{indexer.d.ts → cjs/indexer.d.ts} +0 -0
- /package/dist/{indexer.js → cjs/indexer.js} +0 -0
- /package/dist/{ingestion.d.ts → cjs/ingestion.d.ts} +0 -0
- /package/dist/{ingestion.js → cjs/ingestion.js} +0 -0
- /package/dist/{mcp-server.d.ts → cjs/mcp-server.d.ts} +0 -0
- /package/dist/{mcp-server.js → cjs/mcp-server.js} +0 -0
- /package/dist/{multimodal → cjs/multimodal}/clip-embedder.d.ts +0 -0
- /package/dist/{multimodal → cjs/multimodal}/clip-embedder.js +0 -0
- /package/dist/{multimodal → cjs/multimodal}/index.d.ts +0 -0
- /package/dist/{multimodal → cjs/multimodal}/index.js +0 -0
- /package/dist/{preprocess.d.ts → cjs/preprocess.d.ts} +0 -0
- /package/dist/{preprocess.js → cjs/preprocess.js} +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/index.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/index.js +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mdx.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mdx.js +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mermaid.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mermaid.js +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/registry.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/registry.js +0 -0
- /package/dist/{run-error-recovery-tests.d.ts → cjs/run-error-recovery-tests.d.ts} +0 -0
- /package/dist/{run-error-recovery-tests.js → cjs/run-error-recovery-tests.js} +0 -0
- /package/dist/{search-standalone.d.ts → cjs/search-standalone.d.ts} +0 -0
- /package/dist/{search-standalone.js → cjs/search-standalone.js} +0 -0
- /package/dist/{search.d.ts → cjs/search.d.ts} +0 -0
- /package/dist/{search.js → cjs/search.js} +0 -0
- /package/dist/{test-utils.d.ts → cjs/test-utils.d.ts} +0 -0
- /package/dist/{test-utils.js → cjs/test-utils.js} +0 -0
- /package/dist/{text → cjs/text}/chunker.d.ts +0 -0
- /package/dist/{text → cjs/text}/chunker.js +0 -0
- /package/dist/{text → cjs/text}/embedder.d.ts +0 -0
- /package/dist/{text → cjs/text}/embedder.js +0 -0
- /package/dist/{text → cjs/text}/index.d.ts +0 -0
- /package/dist/{text → cjs/text}/index.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/index.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/index.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mdx.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mdx.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mermaid.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mermaid.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/registry.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/registry.js +0 -0
- /package/dist/{text → cjs/text}/reranker.d.ts +0 -0
- /package/dist/{text → cjs/text}/reranker.js +0 -0
- /package/dist/{text → cjs/text}/sentence-transformer-embedder.d.ts +0 -0
- /package/dist/{text → cjs/text}/sentence-transformer-embedder.js +0 -0
- /package/dist/{text → cjs/text}/tokenizer.d.ts +0 -0
- /package/dist/{text → cjs/text}/tokenizer.js +0 -0
- /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/dist/{types.js → cjs/types.js} +0 -0
- /package/dist/{utils → cjs/utils}/vector-math.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/vector-math.js +0 -0
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORE MODULE — Model Validation and Compatibility System
|
|
3
|
+
* Comprehensive validation system for transformers.js compatibility and model support
|
|
4
|
+
* Provides detailed error messages and suggestions for unsupported models
|
|
5
|
+
*/
|
|
6
|
+
import { ModelRegistry, SUPPORTED_MODELS } from './model-registry.js';
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// TRANSFORMERS.JS VERSION COMPATIBILITY MATRIX
|
|
9
|
+
// =============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Compatibility matrix for different transformers.js versions
|
|
12
|
+
*/
|
|
13
|
+
export const TRANSFORMERS_COMPATIBILITY_MATRIX = {
|
|
14
|
+
'2.6.0': {
|
|
15
|
+
version: '2.6.0',
|
|
16
|
+
supportedFeatures: ['tokenizers', 'text-generation', 'feature-extraction'],
|
|
17
|
+
supportedModelTypes: ['sentence-transformer'],
|
|
18
|
+
knownIssues: ['Limited CLIP support', 'No image processing']
|
|
19
|
+
},
|
|
20
|
+
'2.7.0': {
|
|
21
|
+
version: '2.7.0',
|
|
22
|
+
supportedFeatures: ['tokenizers', 'text-generation', 'feature-extraction', 'image-classification'],
|
|
23
|
+
supportedModelTypes: ['sentence-transformer'],
|
|
24
|
+
knownIssues: ['Experimental CLIP support']
|
|
25
|
+
},
|
|
26
|
+
'2.8.0': {
|
|
27
|
+
version: '2.8.0',
|
|
28
|
+
supportedFeatures: ['tokenizers', 'text-generation', 'feature-extraction', 'image-classification', 'vision'],
|
|
29
|
+
supportedModelTypes: ['sentence-transformer', 'clip'],
|
|
30
|
+
knownIssues: []
|
|
31
|
+
},
|
|
32
|
+
'2.9.0': {
|
|
33
|
+
version: '2.9.0',
|
|
34
|
+
supportedFeatures: ['tokenizers', 'text-generation', 'feature-extraction', 'image-classification', 'vision', 'zero-shot-image-classification'],
|
|
35
|
+
supportedModelTypes: ['sentence-transformer', 'clip'],
|
|
36
|
+
knownIssues: []
|
|
37
|
+
},
|
|
38
|
+
'3.0.0': {
|
|
39
|
+
version: '3.0.0',
|
|
40
|
+
supportedFeatures: ['tokenizers', 'text-generation', 'feature-extraction', 'image-classification', 'vision', 'zero-shot-image-classification', 'image-to-text'],
|
|
41
|
+
supportedModelTypes: ['sentence-transformer', 'clip'],
|
|
42
|
+
knownIssues: []
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
// =============================================================================
|
|
46
|
+
// MODEL VALIDATOR CLASS
|
|
47
|
+
// =============================================================================
|
|
48
|
+
/**
|
|
49
|
+
* Comprehensive model validator with transformers.js compatibility checking
|
|
50
|
+
*/
|
|
51
|
+
export class ModelValidator {
|
|
52
|
+
static currentTransformersVersion = null;
|
|
53
|
+
static systemCapabilities = null;
|
|
54
|
+
/**
|
|
55
|
+
* Set the current transformers.js version for compatibility checking
|
|
56
|
+
* @param version - Current transformers.js version
|
|
57
|
+
*/
|
|
58
|
+
static setTransformersVersion(version) {
|
|
59
|
+
this.currentTransformersVersion = version;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Set system capabilities for compatibility checking
|
|
63
|
+
* @param capabilities - System capabilities
|
|
64
|
+
*/
|
|
65
|
+
static setSystemCapabilities(capabilities) {
|
|
66
|
+
this.systemCapabilities = capabilities;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the current transformers.js version
|
|
70
|
+
* @returns Current version or null if not set
|
|
71
|
+
*/
|
|
72
|
+
static getTransformersVersion() {
|
|
73
|
+
return this.currentTransformersVersion;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Detect transformers.js version from the environment
|
|
77
|
+
* @returns Promise resolving to the detected version or null
|
|
78
|
+
*/
|
|
79
|
+
static async detectTransformersVersion() {
|
|
80
|
+
try {
|
|
81
|
+
// Try to import transformers and get version
|
|
82
|
+
const transformers = await import('@huggingface/transformers');
|
|
83
|
+
// Check if version is available in the package
|
|
84
|
+
if ('version' in transformers && typeof transformers.version === 'string') {
|
|
85
|
+
this.currentTransformersVersion = transformers.version;
|
|
86
|
+
return transformers.version;
|
|
87
|
+
}
|
|
88
|
+
// Fallback: try to read from filesystem package.json
|
|
89
|
+
try {
|
|
90
|
+
const fs = await import('fs');
|
|
91
|
+
const path = await import('path');
|
|
92
|
+
// Try to find the package.json in node_modules
|
|
93
|
+
const packageJsonPath = path.join(process.cwd(), 'node_modules', '@huggingface', 'transformers', 'package.json');
|
|
94
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
95
|
+
const packageContent = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
96
|
+
const packageInfo = JSON.parse(packageContent);
|
|
97
|
+
if (packageInfo.version) {
|
|
98
|
+
this.currentTransformersVersion = packageInfo.version;
|
|
99
|
+
return packageInfo.version;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Filesystem read failed, continue with other methods
|
|
105
|
+
}
|
|
106
|
+
// Fallback: try to detect from package.json import
|
|
107
|
+
try {
|
|
108
|
+
const packageInfo = await import('@huggingface/transformers/package.json' + '');
|
|
109
|
+
if (packageInfo.version) {
|
|
110
|
+
this.currentTransformersVersion = packageInfo.version;
|
|
111
|
+
return packageInfo.version;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Package.json import failed, continue with other methods
|
|
116
|
+
}
|
|
117
|
+
// If we can't detect the version, assume a recent version that should work
|
|
118
|
+
console.warn('Could not detect transformers.js version, assuming 3.7.0 (compatible)');
|
|
119
|
+
this.currentTransformersVersion = '3.7.0';
|
|
120
|
+
return '3.7.0';
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.warn('Transformers.js not found or not importable:', error);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Validate a model with comprehensive compatibility checking
|
|
129
|
+
* @param modelName - Name of the model to validate
|
|
130
|
+
* @param systemCapabilities - Optional system capabilities override
|
|
131
|
+
* @returns Detailed validation result
|
|
132
|
+
*/
|
|
133
|
+
static async validateModelDetailed(modelName, systemCapabilities) {
|
|
134
|
+
const capabilities = systemCapabilities || this.systemCapabilities || undefined;
|
|
135
|
+
// Get basic validation from registry
|
|
136
|
+
const basicValidation = ModelRegistry.validateModel(modelName);
|
|
137
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
138
|
+
if (!basicValidation.isValid) {
|
|
139
|
+
return {
|
|
140
|
+
...basicValidation,
|
|
141
|
+
modelInfo: undefined,
|
|
142
|
+
systemCompatibility: undefined,
|
|
143
|
+
recommendations: {
|
|
144
|
+
alternativeModels: this.getSimilarModels(modelName).length > 0 ?
|
|
145
|
+
this.getSimilarModels(modelName) :
|
|
146
|
+
Object.keys(SUPPORTED_MODELS).slice(0, 3),
|
|
147
|
+
systemUpgrades: [],
|
|
148
|
+
configurationChanges: []
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// Perform detailed compatibility checking
|
|
153
|
+
const systemCompatibility = await this.checkSystemCompatibility(modelInfo, capabilities);
|
|
154
|
+
const recommendations = this.generateRecommendations(modelInfo, systemCompatibility, capabilities);
|
|
155
|
+
// Combine all validation results
|
|
156
|
+
const errors = [...basicValidation.errors];
|
|
157
|
+
const warnings = [...basicValidation.warnings];
|
|
158
|
+
const suggestions = [...basicValidation.suggestions];
|
|
159
|
+
// Add system compatibility errors
|
|
160
|
+
if (!systemCompatibility.transformersJs) {
|
|
161
|
+
errors.push('Transformers.js version incompatibility detected');
|
|
162
|
+
}
|
|
163
|
+
if (!systemCompatibility.memory) {
|
|
164
|
+
errors.push('Insufficient system memory for this model');
|
|
165
|
+
}
|
|
166
|
+
if (!systemCompatibility.platform) {
|
|
167
|
+
errors.push('Model not supported on current platform');
|
|
168
|
+
}
|
|
169
|
+
if (!systemCompatibility.features) {
|
|
170
|
+
errors.push('Required features not available in current transformers.js version');
|
|
171
|
+
}
|
|
172
|
+
// Add recommendations as suggestions
|
|
173
|
+
if (recommendations.alternativeModels.length > 0) {
|
|
174
|
+
suggestions.push(`Alternative models: ${recommendations.alternativeModels.join(', ')}`);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
isValid: errors.length === 0,
|
|
178
|
+
errors,
|
|
179
|
+
warnings,
|
|
180
|
+
suggestions,
|
|
181
|
+
modelInfo: modelInfo || undefined,
|
|
182
|
+
systemCompatibility,
|
|
183
|
+
recommendations
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Validate transformers.js version compatibility for a model
|
|
188
|
+
* @param modelInfo - Model information
|
|
189
|
+
* @param transformersVersion - Transformers.js version to check
|
|
190
|
+
* @returns Validation result
|
|
191
|
+
*/
|
|
192
|
+
static validateTransformersCompatibility(modelInfo, transformersVersion) {
|
|
193
|
+
const version = transformersVersion || this.currentTransformersVersion;
|
|
194
|
+
if (!version) {
|
|
195
|
+
return {
|
|
196
|
+
isValid: false,
|
|
197
|
+
errors: ['Transformers.js version not detected. Please ensure @huggingface/transformers is installed.'],
|
|
198
|
+
warnings: [],
|
|
199
|
+
suggestions: ['Install transformers.js: npm install @huggingface/transformers']
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const requiredVersion = modelInfo.requirements.transformersJsVersion;
|
|
203
|
+
const isCompatible = this.checkVersionCompatibility(version, requiredVersion);
|
|
204
|
+
if (!isCompatible) {
|
|
205
|
+
const compatibilityInfo = this.getCompatibilityInfo(version);
|
|
206
|
+
const supportedModelTypes = compatibilityInfo?.supportedModelTypes || [];
|
|
207
|
+
return {
|
|
208
|
+
isValid: false,
|
|
209
|
+
errors: [
|
|
210
|
+
`Model '${modelInfo.name}' requires transformers.js ${requiredVersion}, but ${version} is installed.`,
|
|
211
|
+
`Current version does not support '${modelInfo.type}' models.`
|
|
212
|
+
],
|
|
213
|
+
warnings: [...(compatibilityInfo?.knownIssues || [])],
|
|
214
|
+
suggestions: [
|
|
215
|
+
`Upgrade transformers.js: npm install @huggingface/transformers@latest`,
|
|
216
|
+
`Supported model types in ${version}: ${supportedModelTypes.join(', ')}`
|
|
217
|
+
]
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const compatibilityInfo = this.getCompatibilityInfo(version);
|
|
221
|
+
const warnings = [];
|
|
222
|
+
const suggestions = [];
|
|
223
|
+
// Check for known issues
|
|
224
|
+
if (compatibilityInfo?.knownIssues.length) {
|
|
225
|
+
warnings.push(...compatibilityInfo.knownIssues);
|
|
226
|
+
}
|
|
227
|
+
// Check if all required features are supported
|
|
228
|
+
const requiredFeatures = modelInfo.requirements.requiredFeatures || [];
|
|
229
|
+
const supportedFeatures = compatibilityInfo?.supportedFeatures || [];
|
|
230
|
+
const missingFeatures = requiredFeatures.filter(feature => !supportedFeatures.includes(feature));
|
|
231
|
+
if (missingFeatures.length > 0) {
|
|
232
|
+
warnings.push(`Some features may not be fully supported: ${missingFeatures.join(', ')}`);
|
|
233
|
+
suggestions.push('Consider upgrading to the latest transformers.js version for full feature support');
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
isValid: true,
|
|
237
|
+
errors: [],
|
|
238
|
+
warnings,
|
|
239
|
+
suggestions
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get all models compatible with a specific transformers.js version
|
|
244
|
+
* @param transformersVersion - Transformers.js version
|
|
245
|
+
* @returns Array of compatible model names
|
|
246
|
+
*/
|
|
247
|
+
static getCompatibleModels(transformersVersion) {
|
|
248
|
+
const version = transformersVersion || this.currentTransformersVersion;
|
|
249
|
+
if (!version)
|
|
250
|
+
return [];
|
|
251
|
+
const compatibilityInfo = this.getCompatibilityInfo(version);
|
|
252
|
+
if (!compatibilityInfo)
|
|
253
|
+
return [];
|
|
254
|
+
return Object.keys(SUPPORTED_MODELS).filter(modelName => {
|
|
255
|
+
const modelInfo = SUPPORTED_MODELS[modelName];
|
|
256
|
+
return compatibilityInfo.supportedModelTypes.includes(modelInfo.type) &&
|
|
257
|
+
this.checkVersionCompatibility(version, modelInfo.requirements.transformersJsVersion);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Get recommended models for a specific use case
|
|
262
|
+
* @param contentTypes - Required content types
|
|
263
|
+
* @param maxMemory - Maximum available memory in MB
|
|
264
|
+
* @param transformersVersion - Transformers.js version
|
|
265
|
+
* @returns Array of recommended model names
|
|
266
|
+
*/
|
|
267
|
+
static getRecommendedModels(contentTypes, maxMemory, transformersVersion) {
|
|
268
|
+
const compatibleModels = this.getCompatibleModels(transformersVersion);
|
|
269
|
+
return compatibleModels.filter(modelName => {
|
|
270
|
+
const modelInfo = SUPPORTED_MODELS[modelName];
|
|
271
|
+
// Check content type support
|
|
272
|
+
const supportsAllTypes = contentTypes.every(type => modelInfo.supportedContentTypes.includes(type));
|
|
273
|
+
if (!supportsAllTypes)
|
|
274
|
+
return false;
|
|
275
|
+
// Check memory requirements
|
|
276
|
+
if (maxMemory && modelInfo.requirements.minimumMemory) {
|
|
277
|
+
if (modelInfo.requirements.minimumMemory > maxMemory)
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
return true;
|
|
281
|
+
}).sort((a, b) => {
|
|
282
|
+
// Sort by memory efficiency (lower memory first)
|
|
283
|
+
const aMemory = SUPPORTED_MODELS[a].requirements.minimumMemory || 0;
|
|
284
|
+
const bMemory = SUPPORTED_MODELS[b].requirements.minimumMemory || 0;
|
|
285
|
+
return aMemory - bMemory;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
// =============================================================================
|
|
289
|
+
// PRIVATE HELPER METHODS
|
|
290
|
+
// =============================================================================
|
|
291
|
+
/**
|
|
292
|
+
* Check system compatibility for a model
|
|
293
|
+
*/
|
|
294
|
+
static async checkSystemCompatibility(modelInfo, capabilities) {
|
|
295
|
+
const transformersJs = capabilities?.transformersJsVersion ?
|
|
296
|
+
this.checkVersionCompatibility(capabilities.transformersJsVersion, modelInfo.requirements.transformersJsVersion) :
|
|
297
|
+
this.currentTransformersVersion ?
|
|
298
|
+
this.checkVersionCompatibility(this.currentTransformersVersion, modelInfo.requirements.transformersJsVersion) :
|
|
299
|
+
false;
|
|
300
|
+
const memory = capabilities?.availableMemory && modelInfo.requirements.minimumMemory ?
|
|
301
|
+
capabilities.availableMemory >= modelInfo.requirements.minimumMemory :
|
|
302
|
+
true; // Assume sufficient if not specified
|
|
303
|
+
const platform = capabilities?.platform && modelInfo.requirements.platformSupport ?
|
|
304
|
+
modelInfo.requirements.platformSupport.includes(capabilities.platform) :
|
|
305
|
+
true; // Assume compatible if not specified
|
|
306
|
+
const features = capabilities?.supportedFeatures && modelInfo.requirements.requiredFeatures ?
|
|
307
|
+
modelInfo.requirements.requiredFeatures.every(feature => capabilities.supportedFeatures.includes(feature)) :
|
|
308
|
+
true; // Assume compatible if not specified
|
|
309
|
+
return { transformersJs, memory, platform, features };
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Generate recommendations based on validation results
|
|
313
|
+
*/
|
|
314
|
+
static generateRecommendations(modelInfo, systemCompatibility, capabilities) {
|
|
315
|
+
const alternativeModels = [];
|
|
316
|
+
const systemUpgrades = [];
|
|
317
|
+
const configurationChanges = [];
|
|
318
|
+
// Suggest alternative models if current one is incompatible
|
|
319
|
+
if (!systemCompatibility.transformersJs || !systemCompatibility.memory) {
|
|
320
|
+
const compatibleModels = this.getCompatibleModels();
|
|
321
|
+
const sameTypeModels = compatibleModels.filter(name => SUPPORTED_MODELS[name].type === modelInfo.type);
|
|
322
|
+
alternativeModels.push(...sameTypeModels.slice(0, 3));
|
|
323
|
+
}
|
|
324
|
+
// Suggest system upgrades
|
|
325
|
+
if (!systemCompatibility.transformersJs) {
|
|
326
|
+
systemUpgrades.push('Upgrade transformers.js to the latest version');
|
|
327
|
+
}
|
|
328
|
+
if (!systemCompatibility.memory && capabilities?.availableMemory && modelInfo.requirements.minimumMemory) {
|
|
329
|
+
const needed = modelInfo.requirements.minimumMemory - capabilities.availableMemory;
|
|
330
|
+
systemUpgrades.push(`Increase available memory by ${needed}MB`);
|
|
331
|
+
}
|
|
332
|
+
// Suggest configuration changes
|
|
333
|
+
if (modelInfo.capabilities.maxBatchSize && modelInfo.capabilities.maxBatchSize < 8) {
|
|
334
|
+
configurationChanges.push(`Use smaller batch sizes (max: ${modelInfo.capabilities.maxBatchSize})`);
|
|
335
|
+
}
|
|
336
|
+
return { alternativeModels, systemUpgrades, configurationChanges };
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Check version compatibility using semantic versioning
|
|
340
|
+
*/
|
|
341
|
+
static checkVersionCompatibility(currentVersion, requiredVersion) {
|
|
342
|
+
// Simple version comparison - in production, use a proper semver library
|
|
343
|
+
const cleanRequired = requiredVersion.replace(/[>=<~^]/g, '');
|
|
344
|
+
const currentParts = currentVersion.split('.').map(Number);
|
|
345
|
+
const requiredParts = cleanRequired.split('.').map(Number);
|
|
346
|
+
// Major version must match or be higher
|
|
347
|
+
if (currentParts[0] > requiredParts[0])
|
|
348
|
+
return true;
|
|
349
|
+
if (currentParts[0] < requiredParts[0])
|
|
350
|
+
return false;
|
|
351
|
+
// Minor version must match or be higher
|
|
352
|
+
if (currentParts[1] > requiredParts[1])
|
|
353
|
+
return true;
|
|
354
|
+
if (currentParts[1] < requiredParts[1])
|
|
355
|
+
return false;
|
|
356
|
+
// Patch version must match or be higher
|
|
357
|
+
return currentParts[2] >= requiredParts[2];
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Get compatibility information for a transformers.js version
|
|
361
|
+
*/
|
|
362
|
+
static getCompatibilityInfo(version) {
|
|
363
|
+
// Find the closest matching version
|
|
364
|
+
const availableVersions = Object.keys(TRANSFORMERS_COMPATIBILITY_MATRIX).sort();
|
|
365
|
+
const matchingVersion = availableVersions.find(v => version.startsWith(v)) ||
|
|
366
|
+
availableVersions[availableVersions.length - 1]; // Default to latest
|
|
367
|
+
return TRANSFORMERS_COMPATIBILITY_MATRIX[matchingVersion] || null;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get similar models for suggestions
|
|
371
|
+
*/
|
|
372
|
+
static getSimilarModels(modelName) {
|
|
373
|
+
const allModels = Object.keys(SUPPORTED_MODELS);
|
|
374
|
+
const lowerModelName = modelName.toLowerCase();
|
|
375
|
+
return allModels.filter(supportedModel => {
|
|
376
|
+
const lowerSupported = supportedModel.toLowerCase();
|
|
377
|
+
// Check for common keywords
|
|
378
|
+
const keywords = ['clip', 'mpnet', 'minilm', 'sentence', 'transformer', 'all', 'base', 'vit'];
|
|
379
|
+
const modelKeywords = keywords.filter(keyword => lowerModelName.includes(keyword));
|
|
380
|
+
const supportedKeywords = keywords.filter(keyword => lowerSupported.includes(keyword));
|
|
381
|
+
return modelKeywords.some(keyword => supportedKeywords.includes(keyword));
|
|
382
|
+
}).slice(0, 3);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// =============================================================================
|
|
386
|
+
// UTILITY FUNCTIONS
|
|
387
|
+
// =============================================================================
|
|
388
|
+
/**
|
|
389
|
+
* Enhanced ModelValidationError class with comprehensive error information
|
|
390
|
+
*/
|
|
391
|
+
export class EnhancedModelValidationError extends Error {
|
|
392
|
+
modelName;
|
|
393
|
+
availableModels;
|
|
394
|
+
errorType;
|
|
395
|
+
suggestions;
|
|
396
|
+
troubleshootingSteps;
|
|
397
|
+
name = 'ModelValidationError';
|
|
398
|
+
constructor(modelName, availableModels, message, errorType = 'not_found', suggestions = [], troubleshootingSteps = []) {
|
|
399
|
+
super(message);
|
|
400
|
+
this.modelName = modelName;
|
|
401
|
+
this.availableModels = availableModels;
|
|
402
|
+
this.errorType = errorType;
|
|
403
|
+
this.suggestions = suggestions;
|
|
404
|
+
this.troubleshootingSteps = troubleshootingSteps;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Get formatted error message with suggestions and troubleshooting steps
|
|
408
|
+
*/
|
|
409
|
+
getFormattedMessage() {
|
|
410
|
+
const lines = [];
|
|
411
|
+
lines.push(`❌ Model Validation Error: ${this.message}`);
|
|
412
|
+
lines.push('');
|
|
413
|
+
if (this.suggestions.length > 0) {
|
|
414
|
+
lines.push('💡 Suggestions:');
|
|
415
|
+
this.suggestions.forEach(suggestion => {
|
|
416
|
+
lines.push(` • ${suggestion}`);
|
|
417
|
+
});
|
|
418
|
+
lines.push('');
|
|
419
|
+
}
|
|
420
|
+
if (this.availableModels.length > 0) {
|
|
421
|
+
lines.push('📋 Available Models:');
|
|
422
|
+
this.availableModels.forEach(model => {
|
|
423
|
+
const modelInfo = SUPPORTED_MODELS[model];
|
|
424
|
+
const typeInfo = modelInfo ? ` (${modelInfo.type}, ${modelInfo.dimensions}d)` : '';
|
|
425
|
+
lines.push(` • ${model}${typeInfo}`);
|
|
426
|
+
});
|
|
427
|
+
lines.push('');
|
|
428
|
+
}
|
|
429
|
+
if (this.troubleshootingSteps.length > 0) {
|
|
430
|
+
lines.push('🔧 Troubleshooting Steps:');
|
|
431
|
+
this.troubleshootingSteps.forEach((step, index) => {
|
|
432
|
+
lines.push(` ${index + 1}. ${step}`);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
return lines.join('\n');
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Log the error with proper formatting
|
|
439
|
+
*/
|
|
440
|
+
logError() {
|
|
441
|
+
console.error(this.getFormattedMessage());
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Enhanced TransformersCompatibilityError class with version information
|
|
446
|
+
*/
|
|
447
|
+
export class EnhancedTransformersCompatibilityError extends Error {
|
|
448
|
+
modelName;
|
|
449
|
+
requiredVersion;
|
|
450
|
+
currentVersion;
|
|
451
|
+
upgradeInstructions;
|
|
452
|
+
alternativeModels;
|
|
453
|
+
name = 'TransformersCompatibilityError';
|
|
454
|
+
constructor(modelName, requiredVersion, currentVersion, message, upgradeInstructions = [], alternativeModels = []) {
|
|
455
|
+
super(message);
|
|
456
|
+
this.modelName = modelName;
|
|
457
|
+
this.requiredVersion = requiredVersion;
|
|
458
|
+
this.currentVersion = currentVersion;
|
|
459
|
+
this.upgradeInstructions = upgradeInstructions;
|
|
460
|
+
this.alternativeModels = alternativeModels;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Get formatted error message with upgrade instructions
|
|
464
|
+
*/
|
|
465
|
+
getFormattedMessage() {
|
|
466
|
+
const lines = [];
|
|
467
|
+
lines.push(`❌ Transformers.js Compatibility Error: ${this.message}`);
|
|
468
|
+
lines.push('');
|
|
469
|
+
lines.push('📊 Version Information:');
|
|
470
|
+
lines.push(` • Required: ${this.requiredVersion}`);
|
|
471
|
+
lines.push(` • Current: ${this.currentVersion}`);
|
|
472
|
+
lines.push('');
|
|
473
|
+
if (this.upgradeInstructions.length > 0) {
|
|
474
|
+
lines.push('⬆️ Upgrade Instructions:');
|
|
475
|
+
this.upgradeInstructions.forEach((instruction, index) => {
|
|
476
|
+
lines.push(` ${index + 1}. ${instruction}`);
|
|
477
|
+
});
|
|
478
|
+
lines.push('');
|
|
479
|
+
}
|
|
480
|
+
if (this.alternativeModels.length > 0) {
|
|
481
|
+
lines.push('🔄 Compatible Alternative Models:');
|
|
482
|
+
this.alternativeModels.forEach(model => {
|
|
483
|
+
const modelInfo = SUPPORTED_MODELS[model];
|
|
484
|
+
const versionInfo = modelInfo ? ` (requires ${modelInfo.requirements.transformersJsVersion})` : '';
|
|
485
|
+
lines.push(` • ${model}${versionInfo}`);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
return lines.join('\n');
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Log the error with proper formatting
|
|
492
|
+
*/
|
|
493
|
+
logError() {
|
|
494
|
+
console.error(this.getFormattedMessage());
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Create a comprehensive model validation error with helpful information
|
|
499
|
+
* @param modelName - Name of the invalid model
|
|
500
|
+
* @param reason - Reason for validation failure
|
|
501
|
+
* @param errorType - Type of validation error
|
|
502
|
+
* @returns Enhanced ModelValidationError instance
|
|
503
|
+
*/
|
|
504
|
+
export function createModelValidationError(modelName, reason, errorType = 'not_found') {
|
|
505
|
+
const availableModels = Object.keys(SUPPORTED_MODELS);
|
|
506
|
+
const message = `Model '${modelName}' validation failed: ${reason}`;
|
|
507
|
+
// Generate contextual suggestions based on error type
|
|
508
|
+
const suggestions = generateModelSuggestions(modelName, errorType);
|
|
509
|
+
const troubleshootingSteps = generateTroubleshootingSteps(errorType);
|
|
510
|
+
return new EnhancedModelValidationError(modelName, availableModels, message, errorType, suggestions, troubleshootingSteps);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Create a comprehensive transformers compatibility error with version information
|
|
514
|
+
* @param modelName - Name of the model
|
|
515
|
+
* @param requiredVersion - Required transformers.js version
|
|
516
|
+
* @param currentVersion - Current transformers.js version
|
|
517
|
+
* @returns Enhanced TransformersCompatibilityError instance
|
|
518
|
+
*/
|
|
519
|
+
export function createTransformersCompatibilityError(modelName, requiredVersion, currentVersion) {
|
|
520
|
+
const message = `Model '${modelName}' requires transformers.js ${requiredVersion}, but ${currentVersion} is installed`;
|
|
521
|
+
// Generate upgrade instructions
|
|
522
|
+
const upgradeInstructions = generateUpgradeInstructions(requiredVersion, currentVersion);
|
|
523
|
+
// Find alternative models compatible with current version
|
|
524
|
+
const alternativeModels = ModelValidator.getCompatibleModels(currentVersion);
|
|
525
|
+
return new EnhancedTransformersCompatibilityError(modelName, requiredVersion, currentVersion, message, upgradeInstructions, alternativeModels);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Initialize the model validator with system detection
|
|
529
|
+
* @returns Promise resolving to initialization success
|
|
530
|
+
*/
|
|
531
|
+
export async function initializeModelValidator() {
|
|
532
|
+
try {
|
|
533
|
+
const version = await ModelValidator.detectTransformersVersion();
|
|
534
|
+
if (version) {
|
|
535
|
+
console.log(`Detected transformers.js version: ${version}`);
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
console.warn('Could not detect transformers.js version');
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
catch (error) {
|
|
544
|
+
console.error('Failed to initialize model validator:', error);
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// =============================================================================
|
|
549
|
+
// HELPER FUNCTIONS FOR ERROR GENERATION
|
|
550
|
+
// =============================================================================
|
|
551
|
+
/**
|
|
552
|
+
* Generate contextual suggestions based on model name and error type
|
|
553
|
+
*/
|
|
554
|
+
function generateModelSuggestions(modelName, errorType) {
|
|
555
|
+
const suggestions = [];
|
|
556
|
+
const lowerModelName = modelName.toLowerCase();
|
|
557
|
+
switch (errorType) {
|
|
558
|
+
case 'not_found':
|
|
559
|
+
// Check for common typos and similar models
|
|
560
|
+
const similarModels = ModelValidator.getSimilarModels(modelName);
|
|
561
|
+
if (similarModels.length > 0) {
|
|
562
|
+
suggestions.push(`Did you mean one of these models?`);
|
|
563
|
+
similarModels.forEach(model => suggestions.push(` • ${model}`));
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
suggestions.push('Check the model name for typos');
|
|
567
|
+
suggestions.push('Ensure the model is supported by transformers.js');
|
|
568
|
+
}
|
|
569
|
+
// Suggest based on apparent intent
|
|
570
|
+
if (lowerModelName.includes('clip')) {
|
|
571
|
+
suggestions.push('For multimodal models, try: Xenova/clip-vit-base-patch32');
|
|
572
|
+
}
|
|
573
|
+
else if (lowerModelName.includes('sentence') || lowerModelName.includes('text')) {
|
|
574
|
+
suggestions.push('For text models, try: sentence-transformers/all-MiniLM-L6-v2');
|
|
575
|
+
}
|
|
576
|
+
break;
|
|
577
|
+
case 'incompatible':
|
|
578
|
+
suggestions.push('Update transformers.js to the latest version');
|
|
579
|
+
suggestions.push('Check the model requirements in the documentation');
|
|
580
|
+
suggestions.push('Consider using a compatible alternative model');
|
|
581
|
+
break;
|
|
582
|
+
case 'unsupported_features':
|
|
583
|
+
suggestions.push('Upgrade transformers.js to get required features');
|
|
584
|
+
suggestions.push('Use a model with fewer feature requirements');
|
|
585
|
+
suggestions.push('Check transformers.js changelog for feature availability');
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
return suggestions;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Generate troubleshooting steps based on error type
|
|
592
|
+
*/
|
|
593
|
+
function generateTroubleshootingSteps(errorType) {
|
|
594
|
+
const steps = [];
|
|
595
|
+
switch (errorType) {
|
|
596
|
+
case 'not_found':
|
|
597
|
+
steps.push('Verify the model name spelling and format');
|
|
598
|
+
steps.push('Check if the model exists on Hugging Face Hub');
|
|
599
|
+
steps.push('Ensure the model is compatible with transformers.js');
|
|
600
|
+
steps.push('Try using a model from the supported models list');
|
|
601
|
+
break;
|
|
602
|
+
case 'incompatible':
|
|
603
|
+
steps.push('Check your current transformers.js version: npm list @huggingface/transformers');
|
|
604
|
+
steps.push('Update to the latest version: npm install @huggingface/transformers@latest');
|
|
605
|
+
steps.push('Clear npm cache if update fails: npm cache clean --force');
|
|
606
|
+
steps.push('Restart your application after updating');
|
|
607
|
+
break;
|
|
608
|
+
case 'unsupported_features':
|
|
609
|
+
steps.push('Check which features are missing in your transformers.js version');
|
|
610
|
+
steps.push('Update transformers.js to get the latest features');
|
|
611
|
+
steps.push('Use alternative models that don\'t require missing features');
|
|
612
|
+
steps.push('Check the transformers.js documentation for feature support');
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
return steps;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Generate upgrade instructions for transformers.js
|
|
619
|
+
*/
|
|
620
|
+
function generateUpgradeInstructions(requiredVersion, currentVersion) {
|
|
621
|
+
const instructions = [];
|
|
622
|
+
// Clean version strings for comparison
|
|
623
|
+
const cleanRequired = requiredVersion.replace(/[>=<~^]/g, '');
|
|
624
|
+
const isSpecificVersion = !requiredVersion.includes('>=');
|
|
625
|
+
if (isSpecificVersion) {
|
|
626
|
+
instructions.push(`Install specific version: npm install @huggingface/transformers@${cleanRequired}`);
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
instructions.push('Update to latest version: npm install @huggingface/transformers@latest');
|
|
630
|
+
instructions.push(`Or install minimum required: npm install @huggingface/transformers@${cleanRequired}`);
|
|
631
|
+
}
|
|
632
|
+
instructions.push('Clear npm cache if needed: npm cache clean --force');
|
|
633
|
+
instructions.push('Restart your application after updating');
|
|
634
|
+
instructions.push('Verify installation: npm list @huggingface/transformers');
|
|
635
|
+
return instructions;
|
|
636
|
+
}
|
|
637
|
+
// =============================================================================
|
|
638
|
+
// ENHANCED VALIDATION FUNCTIONS
|
|
639
|
+
// =============================================================================
|
|
640
|
+
/**
|
|
641
|
+
* Comprehensive model validation with detailed error reporting
|
|
642
|
+
* @param modelName - Name of the model to validate
|
|
643
|
+
* @param options - Validation options
|
|
644
|
+
* @returns Promise resolving to validation result or throws enhanced error
|
|
645
|
+
*/
|
|
646
|
+
export async function validateModelWithDetailedErrors(modelName, options = {}) {
|
|
647
|
+
const { checkTransformersVersion = true, systemCapabilities, throwOnError = false } = options;
|
|
648
|
+
try {
|
|
649
|
+
// Basic model validation
|
|
650
|
+
const basicValidation = ModelRegistry.validateModel(modelName);
|
|
651
|
+
if (!basicValidation.isValid) {
|
|
652
|
+
const error = createModelValidationError(modelName, basicValidation.errors[0], 'not_found');
|
|
653
|
+
if (throwOnError) {
|
|
654
|
+
throw error;
|
|
655
|
+
}
|
|
656
|
+
return {
|
|
657
|
+
...basicValidation,
|
|
658
|
+
modelInfo: undefined,
|
|
659
|
+
systemCompatibility: undefined,
|
|
660
|
+
recommendations: {
|
|
661
|
+
alternativeModels: ModelValidator.getSimilarModels(modelName).length > 0 ?
|
|
662
|
+
ModelValidator.getSimilarModels(modelName) :
|
|
663
|
+
Object.keys(SUPPORTED_MODELS).slice(0, 3),
|
|
664
|
+
systemUpgrades: [],
|
|
665
|
+
configurationChanges: []
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
// Get model info for detailed validation
|
|
670
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
671
|
+
// Check transformers.js compatibility if requested
|
|
672
|
+
if (checkTransformersVersion) {
|
|
673
|
+
const currentVersion = ModelValidator.getTransformersVersion() || await ModelValidator.detectTransformersVersion();
|
|
674
|
+
if (currentVersion) {
|
|
675
|
+
const compatibilityResult = ModelValidator.validateTransformersCompatibility(modelInfo, currentVersion);
|
|
676
|
+
if (!compatibilityResult.isValid) {
|
|
677
|
+
const error = createTransformersCompatibilityError(modelName, modelInfo.requirements.transformersJsVersion, currentVersion);
|
|
678
|
+
if (throwOnError) {
|
|
679
|
+
throw error;
|
|
680
|
+
}
|
|
681
|
+
// Return failed validation result
|
|
682
|
+
return {
|
|
683
|
+
isValid: false,
|
|
684
|
+
errors: compatibilityResult.errors,
|
|
685
|
+
warnings: compatibilityResult.warnings,
|
|
686
|
+
suggestions: compatibilityResult.suggestions,
|
|
687
|
+
modelInfo,
|
|
688
|
+
systemCompatibility: {
|
|
689
|
+
transformersJs: false,
|
|
690
|
+
memory: true,
|
|
691
|
+
platform: true,
|
|
692
|
+
features: false
|
|
693
|
+
},
|
|
694
|
+
recommendations: {
|
|
695
|
+
alternativeModels: ModelValidator.getCompatibleModels(currentVersion),
|
|
696
|
+
systemUpgrades: ['Upgrade transformers.js to the latest version'],
|
|
697
|
+
configurationChanges: []
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
// Perform detailed validation
|
|
704
|
+
return await ModelValidator.validateModelDetailed(modelName, systemCapabilities);
|
|
705
|
+
}
|
|
706
|
+
catch (error) {
|
|
707
|
+
if (error instanceof EnhancedModelValidationError || error instanceof EnhancedTransformersCompatibilityError) {
|
|
708
|
+
throw error;
|
|
709
|
+
}
|
|
710
|
+
// Wrap unexpected errors
|
|
711
|
+
const wrappedError = createModelValidationError(modelName, error instanceof Error ? error.message : String(error), 'incompatible');
|
|
712
|
+
if (throwOnError) {
|
|
713
|
+
throw wrappedError;
|
|
714
|
+
}
|
|
715
|
+
return {
|
|
716
|
+
isValid: false,
|
|
717
|
+
errors: [wrappedError.message],
|
|
718
|
+
warnings: [],
|
|
719
|
+
suggestions: wrappedError.suggestions.slice(),
|
|
720
|
+
modelInfo: undefined,
|
|
721
|
+
systemCompatibility: undefined,
|
|
722
|
+
recommendations: {
|
|
723
|
+
alternativeModels: [],
|
|
724
|
+
systemUpgrades: [],
|
|
725
|
+
configurationChanges: []
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Validate model and provide user-friendly error messages
|
|
732
|
+
* @param modelName - Name of the model to validate
|
|
733
|
+
* @param options - Validation options
|
|
734
|
+
* @returns Promise resolving to true if valid, throws user-friendly error if not
|
|
735
|
+
*/
|
|
736
|
+
export async function validateModelOrThrow(modelName, options = {}) {
|
|
737
|
+
const { logErrors = true } = options;
|
|
738
|
+
try {
|
|
739
|
+
const result = await validateModelWithDetailedErrors(modelName, {
|
|
740
|
+
...options,
|
|
741
|
+
throwOnError: true
|
|
742
|
+
});
|
|
743
|
+
// Log warnings if validation passed but has warnings
|
|
744
|
+
if (result.warnings.length > 0 && logErrors) {
|
|
745
|
+
console.warn('⚠️ Model validation warnings:');
|
|
746
|
+
result.warnings.forEach(warning => console.warn(` • ${warning}`));
|
|
747
|
+
}
|
|
748
|
+
return true;
|
|
749
|
+
}
|
|
750
|
+
catch (error) {
|
|
751
|
+
if (logErrors) {
|
|
752
|
+
if (error instanceof EnhancedModelValidationError || error instanceof EnhancedTransformersCompatibilityError) {
|
|
753
|
+
error.logError();
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
console.error('❌ Model validation failed:', error instanceof Error ? error.message : String(error));
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
// =============================================================================
|
|
763
|
+
// CONSTANTS
|
|
764
|
+
// =============================================================================
|
|
765
|
+
/**
|
|
766
|
+
* Minimum supported transformers.js version
|
|
767
|
+
*/
|
|
768
|
+
export const MIN_TRANSFORMERS_VERSION = '2.6.0';
|
|
769
|
+
/**
|
|
770
|
+
* Recommended transformers.js version
|
|
771
|
+
*/
|
|
772
|
+
export const RECOMMENDED_TRANSFORMERS_VERSION = '2.8.0';
|
|
773
|
+
/**
|
|
774
|
+
* Default system capabilities for validation
|
|
775
|
+
*/
|
|
776
|
+
export const DEFAULT_SYSTEM_CAPABILITIES = {
|
|
777
|
+
platform: 'node',
|
|
778
|
+
availableMemory: 2048, // 2GB default
|
|
779
|
+
gpuSupport: false,
|
|
780
|
+
supportedFeatures: ['tokenizers', 'text-generation', 'feature-extraction']
|
|
781
|
+
};
|
|
782
|
+
//# sourceMappingURL=model-validator.js.map
|