主题
liteparse-server 是一个 Express 服务,把 @llamaindex/liteparse 作为一个 HTTP 解析后端暴露出来。它让 LiteParse 以独立服务的形式运行,适用于:你的应用不是 Node.js、想让多个客户端共用一个解析实例,或者需要把解析端点放在自己的基础设施里。
服务端提供两种形态:
- Slim —— 不含外部依赖的精简构建,最适合上手或嵌入你自己的技术栈。
- Full —— 一体化的方案,内置 Redis 缓存与限流、OpenTelemetry 链路追踪(Jaeger)以及指标(Prometheus + Grafana),并用 Docker Compose 串起来。
两者暴露的端点相同:POST /parse 与 POST /screenshots。
要求
Slim 服务端
src/slim.ts 是服务端的最小版本:去掉了缓存与可观测性,但保留限流与日志。它不需要 Redis,不需要 OpenTelemetry collector,也不需要任何配套服务。
本地运行
克隆 GitHub 仓库之后:
终端窗口
git clone https://github.com/run-llama/liteparse-server
cd liteparse-server可以用 Bun 或 Node 启动这个 API 服务:
终端窗口
bun run start-slim:bun
# or with Node
npm run start-slim:node服务监听 5000 端口。
用 Docker 运行
预构建镜像
可以从 GitHub Container Registry 拉取预构建的 LiteParse(slim)服务端镜像:
终端窗口
docker pull ghcr.io/run-llama/liteparse-server:main然后以暴露 5000 端口的方式运行它:
终端窗口
docker run -p 5000:5000 ghcr.io/run-llama/liteparse-server:main本地构建
如果你克隆了仓库,自带的 slim.Dockerfile 能产出一个自包含的镜像:
终端窗口
# Build the image
docker build -f slim.Dockerfile -t liteparse-server-slim .
# Run exposing port 5000
docker run -p 5000:5000 liteparse-server-slimAPI 随后可在 http://localhost:5000 访问。
完整服务端
若要做生产式部署(带缓存、限流、分布式追踪与指标),请按 examples/docker-compose 里的 Docker Compose 示例来做。它会把服务端连同 Redis、OpenTelemetry Collector、Jaeger、Prometheus 与 Grafana 一起拉起来。
API 规格
基础 URL:http://localhost:5000
POST /parse —— 解析单个文件
解析单个文档,返回结构化的页面数据或纯文本。
表单字段:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
file | file | 是 | 要解析的文档 |
config | string | 否 | JSON 序列化后的 LiteParseConfig 选项 |
查询参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
text | boolean | false | 为 true 时返回 text/plain;否则返回 application/json,其中含 pages 数组 |
响应:
200 text/plain—— 抽取出的文本(当text=true)200 application/json——{ "pages": [...] }(当text=false)400—— 缺少file429—— 超出限流阈值(仅在配置了限流时)
POST /screenshots —— 给文档页面截图
把文档页面渲染为 PNG 图片,并以换行分隔的 JSON(NDJSON)流式返回。
表单字段:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
file | file | 是 | 要截图的文档 |
config | string | 否 | JSON 序列化后的 LiteParseConfig 选项 |
查询参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
pages | string | 全部 | 以逗号分隔的、从 1 开始的页号,例如 1,2,3 |
响应 200 application/x-ndjson —— 每行一个 JSON 对象:
{
"index": 0,
"mimetype": "image/png",
"data": "<base64>",
"page_number": 1,
"height": 1056,
"width": 816
}用 curl 调用的例子
解析文件并拿到 JSON 页面:
终端窗口
curl -X POST http://localhost:5000/parse \
-F "file=@path/to/document.pdf"解析文件并拿到纯文本:
终端窗口
curl -X POST "http://localhost:5000/parse?text=true" \
-F "file=@path/to/document.pdf"传入一个 LiteParseConfig(例如启用 OCR):
终端窗口
curl -X POST http://localhost:5000/parse \
-F "file=@path/to/document.pdf" \
-F 'config={"ocrEnabled":true}'对指定页截图并以 NDJSON 流式返回:
终端窗口
curl -X POST "http://localhost:5000/screenshots?pages=1,2,3" \
-F "file=@path/to/document.pdf"