Skip to content
Snippets Groups Projects
Unverified Commit 46227f2a authored by Alex Yang's avatar Alex Yang Committed by GitHub
Browse files

fix: build error on next.js nodejs runtime (#785)

parent 77f0298f
No related branches found
No related tags found
No related merge requests found
---
"llamaindex": patch
"@llamaindex/edge": patch
---
fix: build error on next.js nodejs runtime
import "llamaindex";
export default function Page() {
return "hello world!";
}
...@@ -3,7 +3,10 @@ import type { ImageType } from "../Node.js"; ...@@ -3,7 +3,10 @@ import type { ImageType } from "../Node.js";
import { MultiModalEmbedding } from "./MultiModalEmbedding.js"; import { MultiModalEmbedding } from "./MultiModalEmbedding.js";
async function readImage(input: ImageType) { async function readImage(input: ImageType) {
const { RawImage } = await import("@xenova/transformers"); const { RawImage } = await import(
/* webpackIgnore: true */
"@xenova/transformers"
);
if (input instanceof Blob) { if (input instanceof Blob) {
return await RawImage.fromBlob(input); return await RawImage.fromBlob(input);
} else if (_.isString(input) || input instanceof URL) { } else if (_.isString(input) || input instanceof URL) {
...@@ -29,7 +32,10 @@ export class ClipEmbedding extends MultiModalEmbedding { ...@@ -29,7 +32,10 @@ export class ClipEmbedding extends MultiModalEmbedding {
async getTokenizer() { async getTokenizer() {
if (!this.tokenizer) { 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); this.tokenizer = await AutoTokenizer.from_pretrained(this.modelType);
} }
return this.tokenizer; return this.tokenizer;
...@@ -37,7 +43,10 @@ export class ClipEmbedding extends MultiModalEmbedding { ...@@ -37,7 +43,10 @@ export class ClipEmbedding extends MultiModalEmbedding {
async getProcessor() { async getProcessor() {
if (!this.processor) { 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); this.processor = await AutoProcessor.from_pretrained(this.modelType);
} }
return this.processor; return this.processor;
...@@ -46,6 +55,7 @@ export class ClipEmbedding extends MultiModalEmbedding { ...@@ -46,6 +55,7 @@ export class ClipEmbedding extends MultiModalEmbedding {
async getVisionModel() { async getVisionModel() {
if (!this.visionModel) { if (!this.visionModel) {
const { CLIPVisionModelWithProjection } = await import( const { CLIPVisionModelWithProjection } = await import(
/* webpackIgnore: true */
"@xenova/transformers" "@xenova/transformers"
); );
this.visionModel = await CLIPVisionModelWithProjection.from_pretrained( this.visionModel = await CLIPVisionModelWithProjection.from_pretrained(
...@@ -59,6 +69,7 @@ export class ClipEmbedding extends MultiModalEmbedding { ...@@ -59,6 +69,7 @@ export class ClipEmbedding extends MultiModalEmbedding {
async getTextModel() { async getTextModel() {
if (!this.textModel) { if (!this.textModel) {
const { CLIPTextModelWithProjection } = await import( const { CLIPTextModelWithProjection } = await import(
/* webpackIgnore: true */
"@xenova/transformers" "@xenova/transformers"
); );
this.textModel = await CLIPTextModelWithProjection.from_pretrained( this.textModel = await CLIPTextModelWithProjection.from_pretrained(
......
import type { BaseNode, Metadata } from "../Node.js"; import type { BaseNode, Metadata } from "../Node.js";
import { TextNode } from "../Node.js"; import { TextNode } from "../Node.js";
import type { BaseRetriever } from "../Retriever.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 type { MessageContent } from "../llm/index.js";
import { extractText } from "../llm/utils.js"; import { extractText } from "../llm/utils.js";
import type { BaseTool } from "../types.js"; import type { BaseTool } from "../types.js";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment