返回顶部
l

llamaparseLlamaParse文档解析

Parse, extract, and analyze documents using the LlamaParse API (LlamaCloud). Use when the user asks to parse PDFs, images, spreadsheets, or other documents into markdown/text/structured data, extract tables or charts from documents, do OCR on scans, batch-process a folder of files, or use LlamaParse for any document processing task. Triggers on phrases like "parse this PDF", "extract text from document", "OCR this scan", "convert PDF to markdown", "extract tables", "parse with LlamaParse", "llam

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.1
安全检测
已通过
210
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

llamaparse

LlamaParse

使用LlamaParse API将文档(PDF、图片、电子表格、演示文稿等130+格式)解析为适用于LLM的文本、Markdown和结构化数据。

前置条件

  • - Python包: llama-cloud>=1.0(pip install llama-cloud)
  • API密钥: 设置LLAMACLOUDAPI_KEY环境变量。在 https://cloud.llamaindex.ai 获取密钥

验证配置:

bash
pip install llama-cloud>=1.0
export LLAMACLOUDAPI_KEY=llx-...

快速开始

python
from llama_cloud import AsyncLlamaCloud
import asyncio

async def parsedocument(filepath: str):
client = AsyncLlamaCloud() # 使用LLAMACLOUDAPI_KEY环境变量
file = await client.files.create(file=file_path, purpose=parse)
result = await client.parsing.parse(
file_id=file.id,
tier=agentic,
version=latest,
expand=[markdown, text],
)
return result

result = asyncio.run(parse_document(document.pdf))
print(result.markdown.pages[0].markdown)

核心概念

层级(必选——选择一项)

层级使用场景成本
agentic_plus最高精度,复杂布局,图表最高
agentic
使用智能代理的高级解析 | 中高 | | cost_effective | 平衡性能与成本 | 中等 | | fast | 最快,基础解析 | 最低 |

始终同时指定tier和version。开发环境使用version=latest,生产环境可复现性使用日期字符串如2026-01-08。

输出视图(expand参数)

在expand列表中请求一个或多个:

  • - markdown — 包含标题、列表、表格的结构化Markdown。最适合RAG/LLM流水线。
  • text — 每页的纯文本。适合搜索/检索。
  • items — 页面元素(标题、段落、表格、图形)的结构化树,包含边界框。适用于布局感知处理。
  • metadata — 文档元数据。
  • imagescontentmetadata — 包含预签名URL的图像/截图元数据。

访问结果:result.markdown.pages[i].markdown、result.text.pages[i].text、result.items.pages[i].items

输出选项

控制Markdown渲染:

python
output_options={
markdown: {
tables: {
outputtablesas_markdown: True, # 或False使用HTML表格
},
},
imagestosave: [screenshot], # 保存页面截图
}

处理选项

python
processing_options={
ignore: {ignorediagonaltext: True},
ocr_parameters: {languages: [en]}, # OCR语言提示
specializedchartparsing: agentic_plus, # 将图表提取为结构化数据
}

自定义提示(代理解析指令)

像指导LLM一样引导解析器——适用于提取特定数据或转换输出:

python
from llamacloud.types.parsingcreate_params import (
ProcessingOptions, ProcessingOptionsAutoModeConfiguration,
ProcessingOptionsAutoModeConfigurationParsingConf
)

result = await client.parsing.parse(
file_id=file.id,
tier=agentic,
version=latest,
expand=[markdown],
processing_options=ProcessingOptions(
automodeconfiguration=[ProcessingOptionsAutoModeConfiguration(
parsing_conf=ProcessingOptionsAutoModeConfigurationParsingConf(
custom_prompt=仅从该收据中提取价格和总额。
)
)]
),
)

常见工作流

解析单个文档

使用scripts/parse_document.py:

bash
python scripts/parse_document.py document.pdf --tier agentic --output markdown,text

批量解析文件夹

使用scripts/batch_parse.py:

bash
python scripts/batch_parse.py ./documents/ --tier agentic --max-concurrent 5

从文档中提取表格

在expand中请求items,然后过滤表格项:

python
for page in result.items.pages:
for item in page.items:
if hasattr(item, rows): # 表格项
print(f第{page.page_number}页的表格:{len(item.rows)}行)
# 可使用item.csv、item.html、item.md

提取图表数据

启用专门的图表解析,然后从图表页面提取表格行:

python
result = await client.parsing.parse(
file_id=file.id,
tier=agentic_plus,
version=latest,
processingoptions={specializedchartparsing: agenticplus},
expand=[items],
)

下载页面截图

python
import httpx, re

result = await client.parsing.parse(
file_id=file.id, tier=agentic, version=latest,
outputoptions={imagesto_save: [screenshot]},
expand=[imagescontentmetadata],
)

for img in result.imagescontentmetadata.images:
if img.presignedurl and re.match(r^page\d+\.jpg$, img.filename):
async with httpx.AsyncClient() as http:
resp = await http.get(img.presigned_url)
with open(img.filename, wb) as f:
f.write(resp.content)

API参考

完整API详情请参阅references/api-reference.md。

外部服务与安全

本技能使用LlamaParse API(https://cloud.llamaindex.ai),这是LlamaIndex提供的云端文档解析服务。

  • - 需要API密钥: 您必须设置LLAMACLOUDAPIKEY环境变量。在 https://cloud.llamaindex.ai 获取密钥。
  • 外部发送数据: 文档会上传到LlamaParse API进行服务端解析。解析结果返回至您的本地机器。
  • 无其他网络调用: 脚本仅与api.cloud.llamaindex.ai通信。截图下载使用同一服务的预签名URL。
  • 脚本为参考工具: scripts/parsedocument.py和scripts/batch_parse.py是辅助脚本,供用户手动运行。它们不会由技能自动执行。

提示

  • - 仅请求您需要的expand视图——更多视图意味着更大的响应和更高的延迟。
  • 对于包含图表/图形的文档,使用agenticplus层级配合specializedchartparsing。
  • 生产环境请固定特定version日期,而非使用latest。
  • 批量解析时使用基于信号量的并发控制以遵守速率限制。
  • items视图为每个元素提供边界框(bbox)——适用于空间分析。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 llamaparse-1776115632 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 llamaparse-1776115632 技能

通过命令行安装

skillhub install llamaparse-1776115632

下载

⬇ 下载 llamaparse v1.0.1(免费)

文件大小: 10.31 KB | 发布时间: 2026-4-15 13:15

v1.0.1 最新 2026-4-15 13:15
Add runtime metadata (requires.env, bins, primaryEnv) to frontmatter and document external service usage to resolve security scan mismatch

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部