**feat: improve TensorFlow.js compatibility and remove unnecessary patches**
- Removed outdated Node.js v24 compatibility patches for `TextEncoder` and `TextDecoder` in `cli-wrapper.js` and other modules since TensorFlow.js now supports Node.js v24+ natively. - Introduced a utility module `src/utils/tensorflowUtils.ts` for TensorFlow.js compatibility, defining global `PlatformNode` and related utilities. - Enhanced `fileSystemStorage.ts` with improved Node.js module loading mechanisms for better compatibility across environments. - Simplified dependency requirements by reducing the minimum Node.js version to `>=23.0.0`. - Updated `package.json`, `cli-package/package.json`, and `README.md` versions to `0.9.25`. - Harmonized `cli-package` and main package dependencies to ensure version alignment. - Improved global compatibility with TensorFlow.js in mixed Node.js environments. This update modernizes TensorFlow.js integration, reduces maintenance efforts, and aligns compatibility with current Node.js and TensorFlow.js capabilities.
This commit is contained in:
parent
16748436d1
commit
eb46d816d7
20 changed files with 428 additions and 168 deletions
|
|
@ -20,6 +20,23 @@ export class UniversalSentenceEncoder implements EmbeddingModel {
|
|||
private use: any = null
|
||||
private backend: string = 'cpu' // Default to CPU
|
||||
|
||||
/**
|
||||
* Add polyfills and patches for TensorFlow.js compatibility
|
||||
* This addresses issues with TensorFlow.js in Node.js environments
|
||||
*/
|
||||
private addNodeCompatibilityPolyfills(): void {
|
||||
// Only apply in Node.js environment
|
||||
if (
|
||||
typeof process === 'undefined' ||
|
||||
!process.versions ||
|
||||
!process.versions.node
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
// No compatibility patches needed - TensorFlow.js now works correctly with Node.js 24+
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the embedding model
|
||||
*/
|
||||
|
|
@ -42,6 +59,9 @@ export class UniversalSentenceEncoder implements EmbeddingModel {
|
|||
originalWarn(message, ...optionalParams)
|
||||
}
|
||||
|
||||
// Add polyfills for TensorFlow.js compatibility
|
||||
this.addNodeCompatibilityPolyfills()
|
||||
|
||||
// TensorFlow.js will use its default EPSILON value
|
||||
|
||||
// Dynamically import TensorFlow.js core module and backends
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue