数据集提取与打包工具

Corpus是一个用于提取和打包数据集并通过MCP服务供LLMs浏览、搜索和检索文件的Python CLI工具。支持YouTube捕获、本地目录或远程GitHub仓库打包、多集合目录和HTTP MCP服务器。

  • by oreofeolurin
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 oreofeolurin/corpus

使用说明

语料库(数据提取、打包和MCP服务)

Corpus是一个Python CLI,用于提取和打包数据集,然后通过MCP提供服务,以便LLM可以浏览、搜索和检索文件。它支持YouTube捕获、打包本地目录或远程GitHub存储库、多集合目录和HTTP MCP服务器。

命令显示为 corpus (主要)和 cpack (包装商别名)。

目录

特性

  • YouTube捕捉:提取 yt-dlp 元数据、字幕/转录本、MP4和通过ffmpeg的屏幕截图;发射 index.json 自动。
  • 打包机(cpack):将目录或远程GitHub仓库打包到一个带有前缀人类索引和可选JSON sidecar的包中;支持包括/排除globs、压缩、gzip/base64。
  • 目录:添加包或目录作为命名集合,并将它们一起提供。
  • HTTP MCP服务器:使用工具将集合暴露给IDE代理(游标等): list_collections, list_files, get_file, search.
  • 批处理、检查、清洁、医生 公用事业。

安装

来自PyPI(推荐)

pipx install corpus-cli

从源代码构建

克隆存储库并在开发模式下安装:

git clone https://github.com/oreofeolurin/corpus.git
cd corpus
make install-dev

这将以可编辑模式安装具有开发依赖关系的包。

独立二进制文件

从GitHub版本下载预构建的可执行文件:

  1. 首选 发布
  2. 下载适用于您平台的二进制文件:
    • corpus-macOS (macOS)
    • corpus-ubuntu (Linux)
    • corpus-windows (Windows)
  3. 制作可执行文件并运行:
    chmod +x corpus-macOS
    ./corpus-macOS --help
    

或者从源代码构建:

make binary
./dist/corpus --help

构建分发包:

make build
# Creates dist/corpus_cli-*.whl and dist/corpus-cli-*.tar.gz

码头工人

使用Docker构建和运行:

docker build -t oreofeolurin/corpus:latest .
docker run --rm -v "$PWD/artifacts:/data" oreofeolurin/corpus:latest capture --url https://www.youtube.com/watch?v=VIDEO_ID --out /data

快速开始

# Check environment
corpus doctor

# Capture one video
corpus capture --url https://www.youtube.com/watch?v=VIDEO_ID --out artifacts/yt --mode scene --max-shots 100

# Inspect the results
corpus inspect --path artifacts/yt/VIDEO_ID --details

# Pack a directory into a single bundle (human index on top)
corpus pack -d artifacts/yt/VIDEO_ID -o artifacts/yt/VIDEO_ID/corpus-out.txt -i "**/*.txt" -i "**/*.info.json"

# Pack a remote GitHub repo subtree and register it in the catalog
corpus pack --repo https://github.com/temporalio/sdk-python/temporalio \
  -i "**/*.py" -o dist/temporal-sdk-python.txt \
  --register-name "Temporal SDK (Python)" --register-tags python,sdk

# Serve the catalog via HTTP MCP (default 127.0.0.1:8787)
corpus mcp serve

# Or point at a single bundle/dir (one-off)
corpus mcp serve --source dist/temporal-sdk-python.txt

命令参考

语料库捕获

捕获YouTube视频的元数据、文字记录和屏幕截图。

旗帜:

  • --url (必填):YouTube观看URL
  • --out (默认值 artifacts/yt):输出基本目录
  • --lang (默认值 en):字幕语言
  • --mode (interval|uniform|scene,默认值 interval)
  • --every (默认值 60):间隔秒数 interval
  • --max-shots (默认值 60):上限或计数 uniform/scene
  • --scene-thresh (默认值 0.3):场景检测阈值
  • --overwrite:覆盖现有文件
  • --no-video, --no-subs, --no-shots:跳过阶段
  • --json:将JSON摘要发送到stdout

输出结构:

<out>/<video_id>/
  ├─ <video_id>.info.json
  ├─ <video_id>.<lang>.vtt (if available)
  ├─ <video_id>.txt (timestamped transcript)
  ├─ <video_id>.mp4
  └─ shots/
       ├─ shot_0001.jpg
       └─ ...

语料库批处理

使用可选的JSONL流处理多个URL。

旗帜:

  • --file PATH 或 --stdin
  • --out, --concurrency, --fail-fast,加上捕获标志
  • --json:将JSONL流式传输到stdout

语料库包(别名:cpack)

将目录或GitHub仓库中的文件打包到单个捆绑包中,可以选择在目录中注册。

旗帜:

  • -d/--dir, -o/--output
  • --repo URL (可选):GitHub URL;支持 /tree/<ref> 和子目录
  • -i/--include GLOB (可重复), -x/--exclude GLOB (可重复)
  • -c/--compress, -m/--max-compress
  • -z/--gzip, -b/--base64 (要求 --gzip)
  • -v/--verbose
  • --config PATH:加载cpack YAML/JSON配置;CLI覆盖文件
  • --write-index (默认为true):在包前添加一个人类可读的索引
  • --index-output PATH (JSON,语料库v1模式)
  • --register-id ID (可选):打包后在目录中注册捆绑包
  • --register-name NAME, --register-tags t1,t2 (可选);如果只提供名称,则会自动生成一个slug ID

语料库mcp(目录和服务器)

  • corpus mcp add --id <id> --source <path> [--type auto|bundle|dir] [--name …] [--tags …]
  • corpus mcp rm --id <id>
  • corpus mcp ls
  • corpus mcp serve [--source <path>] [--host 127.0.0.1] [--port 8787]

MCP工具(HTTP):

  • list_collections → 线条 <id>\t<type>\t<source>
  • list_files {collection} → 集合中的文件路径
  • get_file {collection, path, start?, end?} → 文件内容(可选行范围)
  • search {collection, query, top_k?, case_sensitive?} → path:line: snippet

语料库检查

总结工件目录(--details 元数据字段)。

语料库清理

删除方式 --id 在...之下 --out 或一切与 --all (由守卫 --yes).

语料库医生

检查 yt-dlp, ffmpeg, ffprobe,以及Python依赖关系。

配置

打包器配置(cpack)

您可以使用 cpack.yml, cpack.yaml,或 cpack.json 在输入目录中,或指定 --config.

YAML示例:

inputDir: ./src
outputFile: output.txt
includeGlobs:
  - "**/*.py"
  - "**/*.md"
excludeGlobs:
  - "**/.git/**"
  - "**/node_modules/**"
verbose: true
compress: false
maxCompress: false
gzip: false
base64: false

JSON示例:

{
  "inputDir": "./src",
  "outputFile": "output.txt",
  "includeGlobs": ["**/*.py", "**/*.md"],
  "excludeGlobs": ["**/.git/**", "**/node_modules/**"],
  "verbose": true,
  "compress": false,
  "maxCompress": false,
  "gzip": false,
  "base64": false
}

输出格式

Packer支持多种格式:

  1. 标准文本(默认)
  2. 压缩空白(--compress)
  3. 带注释删除的最大压缩(--max-compress)
  4. Gzip压缩字节数(--gzip)
  5. gzip的Base64(--gzip --base64)

例子

  1. 间隔捕捉;每分钟最多20次射击:
corpus capture --url https://www.youtube.com/watch?v=VIDEO_ID \
  --out artifacts/yt --mode interval --every 60 --max-shots 20
  1. 基于场景的拍摄(约100张):
corpus capture --url https://www.youtube.com/watch?v=VIDEO_ID \
  --out artifacts/yt --mode scene --scene-thresh 0.3 --max-shots 100
  1. 使用JSONL输出从文件批处理:
corpus batch --file urls.txt --out artifacts/yt --concurrency 4 --json
  1. 封隔器包括/不包括压缩和对齐:
corpus pack -d artifacts/yt/VIDEO_ID -o artifacts/yt/VIDEO_ID/corpus-out.txt \
  -i "**/*.txt" -i "**/*.info.json" -x "**/shots/**" -c -v \
  --register-name "My Video Artifacts" --register-tags video,youtube

故障排除

  • ffmpeg not found:通过Homebrew安装(brew install ffmpeg)或者您的操作系统包管理器。
  • yt-dlp 问题/费率限制:提供Cookie(--cookies 通过未来的捕获),使用代理(--proxy 以后)或稍后重新运行。
  • 权限:确保输出目录可写。
  • Docker:使用提供的Dockerfile来避免本地依赖问题。

贡献

欢迎投稿!看 贡献.md 用于开发、测试和发布指南。

许可证

根据 MIT许可证.