diff --git a/.changeset/real-ears-design.md b/.changeset/real-ears-design.md new file mode 100644 index 0000000000000000000000000000000000000000..307b1a96f652596dda174c7d41adaba83e996f06 --- /dev/null +++ b/.changeset/real-ears-design.md @@ -0,0 +1,5 @@ +--- +"@llamaindex/cloud": patch +--- + +fix(cloud): llama parse reader save image incorrectly diff --git a/packages/cloud/src/reader.ts b/packages/cloud/src/reader.ts index 7731cd5f4d3c59c781c5523a07f40da0631c9a5d..88c0fac38a9e350d9552b0261bb4cfc66cb14f69 100644 --- a/packages/cloud/src/reader.ts +++ b/packages/cloud/src/reader.ts @@ -1,11 +1,11 @@ -import { createClient, createConfig, type Client } from "@hey-api/client-fetch"; +import { type Client, createClient, createConfig } from "@hey-api/client-fetch"; import { Document, FileReader } from "@llamaindex/core/schema"; -import { fs, getEnv } from "@llamaindex/env"; +import { fs, getEnv, path } from "@llamaindex/env"; import { filetypeinfo } from "magic-bytes.js"; import { - ParsingService, type Body_upload_file_api_v1_parsing_upload_post, type ParserLanguages, + ParsingService, } from "./api"; import { sleep } from "./utils"; @@ -510,14 +510,7 @@ export class LlamaParseReader extends FileReader { jobId: string, imageName: string, ): Promise<string> { - // Get the full path - let imagePath = `${downloadPath}/${jobId}-${imageName}`; - // Get a valid image path - if (!imagePath.endsWith(".png") && !imagePath.endsWith(".jpg")) { - imagePath += ".png"; - } - - return imagePath; + return path.join(downloadPath, `${jobId}-${imageName}`); } private async fetchAndSaveImage( @@ -538,10 +531,9 @@ export class LlamaParseReader extends FileReader { if (response.error) { throw new Error(`Failed to download image: ${response.error.detail}`); } - const arrayBuffer = (await response.data) as ArrayBuffer; - const buffer = new Uint8Array(arrayBuffer); + const blob = (await response.data) as Blob; // Write the image buffer to the specified imagePath - await fs.writeFile(imagePath, buffer); + await fs.writeFile(imagePath, new Uint8Array(await blob.arrayBuffer())); } // Filters out invalid values (null, undefined, empty string) of specific params.