Skip to content

Commit

Permalink
fix: build error on next.js nodejs runtime (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 authored May 1, 2024
1 parent 77f0298 commit 46227f2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-penguins-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"llamaindex": patch
"@llamaindex/edge": patch
---

fix: build error on next.js nodejs runtime
5 changes: 5 additions & 0 deletions packages/core/e2e/examples/nextjs-agent/src/app/test/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "llamaindex";

export default function Page() {
return "hello world!";
}
17 changes: 14 additions & 3 deletions packages/core/src/embeddings/ClipEmbedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import type { ImageType } from "../Node.js";
import { MultiModalEmbedding } from "./MultiModalEmbedding.js";

async function readImage(input: ImageType) {
const { RawImage } = await import("@xenova/transformers");
const { RawImage } = await import(
/* webpackIgnore: true */
"@xenova/transformers"
);
if (input instanceof Blob) {
return await RawImage.fromBlob(input);
} else if (_.isString(input) || input instanceof URL) {
Expand All @@ -29,15 +32,21 @@ export class ClipEmbedding extends MultiModalEmbedding {

async getTokenizer() {
if (!this.tokenizer) {
const { AutoTokenizer } = await import("@xenova/transformers");
const { AutoTokenizer } = await import(
/* webpackIgnore: true */
"@xenova/transformers"
);
this.tokenizer = await AutoTokenizer.from_pretrained(this.modelType);
}
return this.tokenizer;
}

async getProcessor() {
if (!this.processor) {
const { AutoProcessor } = await import("@xenova/transformers");
const { AutoProcessor } = await import(
/* webpackIgnore: true */
"@xenova/transformers"
);
this.processor = await AutoProcessor.from_pretrained(this.modelType);
}
return this.processor;
Expand All @@ -46,6 +55,7 @@ export class ClipEmbedding extends MultiModalEmbedding {
async getVisionModel() {
if (!this.visionModel) {
const { CLIPVisionModelWithProjection } = await import(
/* webpackIgnore: true */
"@xenova/transformers"
);
this.visionModel = await CLIPVisionModelWithProjection.from_pretrained(
Expand All @@ -59,6 +69,7 @@ export class ClipEmbedding extends MultiModalEmbedding {
async getTextModel() {
if (!this.textModel) {
const { CLIPTextModelWithProjection } = await import(
/* webpackIgnore: true */
"@xenova/transformers"
);
this.textModel = await CLIPTextModelWithProjection.from_pretrained(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/objects/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BaseNode, Metadata } from "../Node.js";
import { TextNode } from "../Node.js";
import type { BaseRetriever } from "../Retriever.js";
import type { VectorStoreIndex } from "../indices/index.js";
import type { VectorStoreIndex } from "../indices/vectorStore/index.js";
import type { MessageContent } from "../llm/index.js";
import { extractText } from "../llm/utils.js";
import type { BaseTool } from "../types.js";
Expand Down

0 comments on commit 46227f2

Please sign in to comment.