Skip to content

Commit

Permalink
Fix [ERR_REQUIRE_ESM] error when importing hf_transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
JonaMX committed Jun 12, 2024
1 parent ac204f8 commit bc934b1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libs/langchain-community/src/embeddings/hf_transformers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Pipeline, pipeline } from "@xenova/transformers";
import { Pipeline } from "@xenova/transformers";
import { Embeddings, type EmbeddingsParams } from "@langchain/core/embeddings";
import { chunkArray } from "@langchain/core/utils/chunk_array";
const TransformersApi = Function('return import("@xenova/transformers")')();


export interface HuggingFaceTransformersEmbeddingsParams
extends EmbeddingsParams {
Expand Down Expand Up @@ -100,6 +102,7 @@ export class HuggingFaceTransformersEmbeddings
}

private async runEmbedding(texts: string[]) {
const { pipeline } = await TransformersApi;
const pipe = await (this.pipelinePromise ??= pipeline(
"feature-extraction",
this.model
Expand Down

0 comments on commit bc934b1

Please sign in to comment.