unstructured 在版本 >=0.11.4 中,`bug/get_elements_from_api()` 函数出现了错误,不支持文件类型 None,

7dl7o3gd  于 2个月前  发布在  其他
关注(0)|答案(4)|浏览(36)

描述bug

我使用以下参数调用 get_elements_from_api() 函数。

file = <some byte stream>  # downloaded from the AWS S3

documents = get_elements_from_api(
    file_path=None,
    api_key='<api-key>',
    api_url='<api-url>',
    file=file,  # BytesIO type. just a simple pdf file that contains only text
    mode='elements',
    content_type='application/pdf',  # corresponding MIME type with file
    metadata_filename='asdf',  # filename, but without extension (e.g. .pdf)
)

0.11.2 版本中没有问题。unstructured 使用 content_type 识别文件类型并将 metadata_filename 存储在元素元数据中。
然而,从 >=0.11.4 开始,它的行为不符合预期。它开始出现 File type None is not supported. 错误。
我仔细研究了代码,发现从 0.11.4 开始,在 unstructured/partition/api.py line 83 ~ 86 中,似乎 metadata_filename 被分配给了 file_name 并传递给了 unstructured API server

files = shared.Files(
            content=file,
            file_name=metadata_filename,
        )

最后,unstructured 似乎使用 file_name 而不是 content_type 来识别文件类型(你也可以通过从 get_elements_from_api() API 中删除 content_type 参数来检查 unstructured 不使用 content_type)。
以下代码在 >=0.11.4 中运行正常(但并非预期)。

documents = get_elements_from_api(
    file_path=None,
    api_key='<api-key>',
    api_url='<api-url>',
    file=file,  # BytesIO type
    mode='elements',
    # content_type='application/pdf',  # corresponding MIME type with file
    metadata_filename='asdf.pdf',  # filename with extension
)

重现

  • 传递带有字节流的文件。
  • 设置正确的 content_type。
  • metadata_filename 中不设置扩展名。
file = <some byte stream>  # which is downloaded from the AWS S3

documents = get_elements_from_api(
    file_path=None,
    api_key='<api-key>',
    api_url='<api-url>',
    file=file,  # BytesIO type
    mode='elements',
    content_type='application/pdf',  # corresponding MIME type with file
    metadata_filename='asdf',  # filename, but there's no extension
)

预期行为

  • 0.11.2 中,没有错误。
  • >=0.11.4 中,出现 File type None is not supported. 错误。

总之,我希望 unstructured 能够像 0.11.2 一样工作,即从 content_type 中识别文件类型并可以使用带或不带扩展名的 metadata_filename

截图

如果适用,请添加截图以帮助解释您的问题。

环境信息

我还在不同的操作系统(如 Ubuntu、macOS)上进行了测试,并使用了最新的 unstructured 版本。

OS version:  Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python version:  3.11.6
unstructured version:  0.11.4
unstructured-inference is not installed
pytesseract version:  0.3.10
Torch version:  2.1.1+cu118
Detectron2 is not installed
PaddleOCR is not installed
Libmagic version: file-5.41
magic file from /etc/magic:/usr/share/misc/magic
LibreOffice version:  LibreOffice 7.3.7.2 30(Build:2)

附加上下文

无论如何,感谢维护这个史诗般的项目。我是 unstructured 的大粉丝 :)

gzszwxb4

gzszwxb41#

你好!请问您有空时能帮忙检查这个问题吗?非常感谢您的帮助!

6psbrbz9

6psbrbz92#

抱歉让这件事漏掉!我会尽快回复你。

8ftvxx2r

8ftvxx2r3#

@kozistr,content-type正在计划中,一旦我们migrate the python SDK to v2,就会得到Python SDK的支持。partition_via_api取决于客户端,所以一旦合并,这个问题就会得到解决。

yfwxisqw

yfwxisqw4#

@kozistr,content-type已经在路线图上,一旦我们migrate the python SDK to v2,就会支持python SDK。partition_via_api取决于客户端,所以一旦合并,这个问题就会得到解决。感谢你告诉我:)

相关问题