ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;">现在LLM(大型语言模型)应用的普遍使用和落地,Markdown格式的文档是各种LLM和RAG(检索增强生成)偏爱,主要体现在以下两个方面:ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;"> ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;list-style-type: disc;visibility: visible;" class="list-paddingleft-1">首先,Markdown是一种轻量级的标记语言,具备简洁性和易读易写的特点,使得它成为编写和存储文档的理想选择,特别是当这些文档需要通过LLM进行处理或通过RAG模型进行增强时。 ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;visibility: visible;"> ingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;list-style-type: disc;visibility: visible;" class="list-paddingleft-1">其次,Markdown的结构化特性使其在进行文本处理时更加高效。例如,向量化文档时,需要根据标题层级对Markdown文件进行结构化分割,这种规范的结构化分割保留了文本的上下文和结构信息,这对于RAG模型来说非常重要,有助于提升文本向量化和RAG检索的效果。 所以文件格式的转换变得尤为重要。无论是将PDF、Word文档,还是Excel表格、PPT演示文稿进行结构化处理,很多时候我们都需要将其处理为Markdown格式今天,我们要介绍的就是这款由微软开源的多功能文档转换工具—MarkItDown。一个轻量级的 Python 实用程序,主要用于将各种文件转换为 Markdown 格式,以便与大语言模型(LLMs)和相关文本分析管道配合使用。与传统的文本提取工具相比,MarkItDown 更注重保留重要的文档结构和内容,如标题、列表、表格、链接等。虽然它的输出主要是为了供文本分析工具使用,但对于需要快速将多种文件格式转换为 Markdown 的用户来说,它无疑是一个强大的工具。ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.544px;text-wrap: wrap;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 16px;text-align: left;visibility: visible;">? 项目信息#GitHub地址https://github.com/microsoft/markitdown ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.544px;text-wrap: wrap;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 16px;text-align: left;visibility: visible;">ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 16px;text-align: left;visibility: visible;">?ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.544px;text-wrap: wrap;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 16px;text-align: left;visibility: visible;">功能特性 ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;letter-spacing: 0.544px;visibility: visible;">1. 多格式支持 MarkItDown 支持的文件格式丰富多样,涵盖了常见的办公和多媒体文件类型,包括: PDF PowerPoint Word Excel 图像(EXIF 元数据和 OCR) 音频(EXIF 元数据和语音转录) HTML 基于文本的格式(CSV、JSON、XML) ZIP 文件 Youtube 网址 EPubs
2. 灵活的配置选项 可选依赖项:MarkItDown 提供了多种可选依赖项,用户可以根据需要安装特定的依赖项,例如pip install markitdown[pdf, docx, pptx]只安装 PDF、DOCX 和 PPTX 文件的依赖项。 插件支持:MarkItDown 支持第三方插件,用户可以通过插件扩展其功能。插件默认是禁用的,可以通过markitdown --use-plugins命令启用。
3. 与大语言模型的集成 MarkItDown 支持与 GPT-4 等大语言模型集成,可以生成丰富的描述性输出,例如对图片的分析和描述。用户可以通过提供llm_client和llm_model参数来启用这一功能。
4. 其他特性 通过简单的 pip 命令即可快速安装 MarkItDown
pipinstall'markitdown[all]' gitclonegit@github.com:microsoft/markitdown.gitcdmarkitdownpipinstall-epackages/markitdown[all] 1. 命令行使用 markitdownpath-to-file.pdf markitdownpath-to-file.pdf-odocument.md catpath-to-file.pdf|markitdown
2. Python API 使用 frommarkitdownimportMarkItDownmd=MarkItDown(enable_plugins=False)#禁用插件result=md.convert("test.xlsx")print(result.text_content)
frommarkitdownimportMarkItDownfromopenaiimportOpenAIclient=OpenAI()md=MarkItDown(llm_client=client,llm_model="gpt-4o")result=md.convert("example.jpg")print(result.text_content)
3. Docker 使用 dockerbuild-tmarkitdown:latest.
dockerrun--rm-imarkitdown:latest<~/your-file.pdf>output.md MarkItDown 作为一个强大的文件转换工具,为用户提供了丰富的功能和便捷的使用方式。它支持多种文件格式的转换,并且通过插件架构,使得其功能可以不断扩展,满足不同用户的多样化需求。 |