transformers.js icon indicating copy to clipboard operation
transformers.js copied to clipboard

fix: `RawImage.fromURL` error when input file url

Open himself65 opened this issue 8 months ago • 5 comments

Upstream: https://github.com/run-llama/LlamaIndexTS/pull/1855

fs.existSync(path) will assume path is a posix/win32 format if you give a string, so you will need pass url.pathname

himself65 avatar Apr 16 '25 17:04 himself65

/cc @xenova do you have a change to look at this? /

himself65 avatar Apr 21 '25 21:04 himself65

Hi @himself65 👋 Can you give an example of a URL which has this problem? The if clause should not allow invalid URLs to pass this step.

xenova avatar Apr 21 '25 21:04 xenova

Hi @himself65 👋 Can you give an example of a URL which has this problem? The if clause should not allow invalid URLs to pass this step.

Yes, we were using file: protocol in node.js, and file protocol is a standard in node.js. And this is a regression because our test is working in <=4.0.0

const imageUrl = new URL(
  "../../fixtures/img/llamaindex-white.png",
  import.meta.url,
);

const nodes = [
  new ImageNode({
    image: imageUrl,
  }),
];

himself65 avatar Apr 21 '25 21:04 himself65

Docs: https://nodejs.org/api/fs.html#file-url-paths

himself65 avatar Apr 21 '25 21:04 himself65

That's a valid use-case, thanks for reporting! This will be merged in v3.5.1 💪

xenova avatar Apr 24 '25 01:04 xenova

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.