Oculith 文档处理工具
简介
Oculith 是一个强大的文档处理工具,可以将多种格式的文档(如PDF、Word、HTML等)转换为Markdown等结构化格式。它既可以作为独立服务运行,也可以集成到你的应用中。
功能特点
- 支持多种文档格式(PDF、Word、HTML、图片等)
- 文档转换为Markdown、文本等格式
- 文档自动分块与向量化处理
- 基于语义相似度的文档搜索
- 异步处理和任务队列管理
- 实时处理状态监控
- RESTful API接口便于集成
安装方法
pip install oculith
快速开始
作为服务启动
最简单的方式是直接运行Oculith服务:
python -m oculith
这将在默认端口(31573)启动服务。你可以通过以下选项自定义:
# 指定端口
python -m oculith --port 8080
# 指定允许的文档格式
python -m oculith --allowed-formats pdf,docx,html
# 指定输出目录
python -m oculith --output-dir ./文档输出
API使用方法
服务启动后,你可以通过以下API进行文档处理:
1. 上传并处理文档
POST /oculith/files/upload
使用表单提交:
file: 要上传的文件title: 可选的文档标题description: 可选的文档描述tags: 可选的标签列表auto_process: 是否自动处理(true/false)
2. 收藏远程URL文件
POST /oculith/files/bookmark-remote
提交参数:
url: 远程文件的URL地址filename: 可选的文件名title: 可选的文档标题description: 可选的文档描述tags: 可选的标签列表auto_process: 是否自动处理(true/false)
3. 手动启动文件处理
POST /oculith/files/{file_id}/process
提交参数:
step: 处理步骤(convert/chunk/index/all)priority: 任务优先级(数字)
4. 获取支持的格式
GET /oculith/formats
5. 获取文件列表
GET /oculith/files
文件管理功能
Oculith 提供了完整的文件管理功能:
- 获取文件列表:
GET /oculith/files - 获取文件信息:
GET /oculith/files/{file_id} - 获取Markdown内容:
GET /oculith/files/{file_id}/markdown - 更新文件元数据:
PATCH /oculith/files/{file_id} - 删除文件:
DELETE /oculith/files/{file_id} - 下载文件:
GET /oculith/files/{file_id}/download - 监控处理状态:
GET /oculith/files/{file_id}/process/stream(SSE流) - 获取存储状态:
GET /oculith/files/storage/status
任务管理
Oculith 支持异步任务管理:
- 获取任务状态:
GET /oculith/tasks/{task_id} - 取消任务:
POST /oculith/tasks/{task_id}/cancel - 队列诊断:
GET /oculith/queue/diagnostics
搜索功能
Oculith 支持基于向量相似度的语义检索:
- 检索内容片段:
POST /oculith/search/chunks - 检索相似文档:
POST /oculith/search/documents
使用示例
使用curl上传并处理文档
curl -X POST "http://localhost:31573/oculith/files/upload" \
-F "file=@/路径/文档.pdf" \
-F "title=测试文档" \
-F "description=这是一个测试文档" \
-F "auto_process=true"
收藏远程URL
curl -X POST "http://localhost:31573/oculith/files/bookmark-remote" \
-F "url=https://example.com/document.pdf" \
-F "title=远程文档" \
-F "auto_process=true"
监控处理状态(前端代码)
// 使用EventSource监听处理状态
const eventSource = new EventSource(
'http://localhost:31573/oculith/files/FILE_ID/process/stream',
{ headers: { 'Authorization': 'Bearer 你的令牌' } }
);
eventSource.addEventListener('status', (event) => {
const data = JSON.parse(event.data);
console.log(`处理状态: ${data.status}`);
});
eventSource.addEventListener('complete', (event) => {
console.log('处理完成');
eventSource.close();
});
检索相似内容
curl -X POST "http://localhost:31573/oculith/search/chunks" \
-F "query=关键词搜索" \
-F "threshold=0.7" \
-F "limit=5"
集成到其他应用
Oculith可以轻松集成到现有的FastAPI应用中:
from fastapi import FastAPI
from oculith.api.endpoints import mount_docling_service
app = FastAPI()
# 挂载Oculith服务
mount_docling_service(
app=app,
output_dir="./data/oculith",
allowed_formats=["pdf", "docx", "html", "md"],
prefix="/api" # API端点前缀
)
注意事项
- 第一次使用时需要设置环境变量
FASTAPI_SECRET_KEY作为认证密钥 - 对于大文件处理,可能需要更长的处理时间
- 默认情况下,每个用户的存储限制为200MB
- 任务队列默认最大并发数为3,可根据服务器资源调整
- 服务重启后任务队列会重置,请妥善管理任务状态
更多帮助
启动服务后,你可以访问 http://localhost:31573/docs 获取完整的API文档。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
oculith-0.1.3.tar.gz
(47.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
oculith-0.1.3-py3-none-any.whl
(52.5 kB
view details)
File details
Details for the file oculith-0.1.3.tar.gz.
File metadata
- Download URL: oculith-0.1.3.tar.gz
- Upload date:
- Size: 47.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.0.0 CPython/3.11.7 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11756e6ad0b4cecf00eb19687e8a304a3e1e462b776ce055072c4b31e60bc8e6
|
|
| MD5 |
80e01b7628d2adde2ec4aee37e63372e
|
|
| BLAKE2b-256 |
84dacc0f543fd9fa5dfa045db0f30764c10c04576acd17c9dcd83262495e345c
|
File details
Details for the file oculith-0.1.3-py3-none-any.whl.
File metadata
- Download URL: oculith-0.1.3-py3-none-any.whl
- Upload date:
- Size: 52.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.0.0 CPython/3.11.7 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f301df84b5a78ad86f755671d267e2923324b6e4f6413200945cec1ede40562
|
|
| MD5 |
1d84edc3fdda6214571da02927421380
|
|
| BLAKE2b-256 |
923b9186bc7ea9ab0d78cbf950b019059c35ad37b07da2c907f28d698d0d4554
|