llama_index [Bug]: AsyncWebPageReader指出,pdf-urls或重定向到pdf的urls无效,

ikfrs5lh  于 23天前  发布在  其他
关注(0)|答案(1)|浏览(22)

Bug描述

当使用AsyncWebPageReader的aload方法,并且其中一个url是:

  • 一个指向.pdf文件的直接url
  • 一个重定向到.pdf文件的url

那么aload方法会抛出一个异常,指出“输入中的一个不是有效的url”。
当使用SimpleWebPageReader的load方法时,似乎可以正常工作。
我使用的是Python 3.12和llama-index-readers-web版本0.2.1。

版本

0.11.1

重现步骤

执行以下代码:

from llama_index.readers.web import AsyncWebPageReader, SimpleWebPageReader
import asyncio

async def test_async():
    async_reader = AsyncWebPageReader()
    docs = await async_reader.aload_data(urls=[
        "https://docs.llamaindex.ai/en/stable/api_reference/readers/web/#llama_index.readers.web.AsyncWebPageReader",
        "https://www.llamaindex.ai/files/privacy-notice.pdf"
    ])

def test():
    simple_reader = SimpleWebPageReader()
    docs = simple_reader.load_data(urls=[
        "https://docs.llamaindex.ai/en/stable/api_reference/readers/web/#llama_index.readers.web.AsyncWebPageReader",
        "https://www.llamaindex.ai/files/privacy-notice.pdf"
    ])
# Works
test()
#Does not work. Error: "ValueError: One of the inputs is not a valid url: https://www.llamaindex.ai/files/privacy-notice.pdf"
asyncio.run(test_async())

相关日志/回溯

Traceback (most recent call last):
  File "llamatest/main.py", line 21, in <module>
    asyncio.run(test_async())
  File "/usr/lib64/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "llamatest/main.py", line 7, in test_async
    docs = await async_reader.aload_data(urls=[
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "llamatest/venv/lib64/python3.12/site-packages/llama_index/readers/web/async_web/base.py", line 88, in aload_data
    raise ValueError(f"One of the inputs is not a valid url: {urls[i]}")
ValueError: One of the inputs is not a valid url: https://www.llamaindex.ai/files/privacy-notice.pdf
2fjabf4q

2fjabf4q1#

你好@lucas-trueffles!我在这里帮助你解决任何bug、问题或贡献。让我们一起解决你面临的问题。
aload 方法在给定一个指向 .pdf 文件的直接URL或重定向到 .pdf 文件的URL时,会抛出一个“输入中的一个不是有效的url”异常,因为该方法期望响应是一个包含响应对象和原始页面内容(文本)的元组。如果URL指向一个 .pdf 文件,响应内容不是文本,这会导致方法在类型检查中失败并引发异常。
以下是相关代码的一部分:

for i, response_tuple in enumerate(responses):
    if not isinstance(response_tuple, tuple):
        raise ValueError(f"One of the inputs is not a valid url: {urls[i]}")

相比之下,load 方法可能没有如此严格的类型检查,或者可能以不同的方式处理非文本响应,使其能够与 .pdf URL 1(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/readers/llama-index-readers-web/llama_index/readers/web/async_web/base.py) 正常工作。

  • 要继续与 Dosu 交流,请提及 @dosu。*

相关问题