mcpField
D
doc-pipeline

doc-pipeline

github.com/claude-office-skills文档处理5454.6k 次安装39 周前更新
代码仓库

关于 doc-pipeline

doc-pipeline 是用于构建文档处理管道的技能,可将提取、转换和生成等操作串联为可复用工作流。适合需要处理文档、表格或图像并输出成品的场景,也提供 YAML DSL 和 Python 实现示例。

主要功能

  1. 01串联提取、转换与输出阶段
  2. 02支持数据在阶段间流转
  3. 03通过 YAML 配置管道
  4. 04支持条件处理阶段
  5. 05提供 Python 实现示例

适用场景

  1. 01提取 PDF 文本并翻译后生成 DOCX
  2. 02对图像执行 OCR、摘要并生成报告
  3. 03分析 Excel 数据并制作图表和 PPT
  4. 04合并多个输入并格式化输出

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/claude-office-skills/skills --skill doc-pipeline

安装后在 Claude Code 中输入/doc-pipeline确认已加载。

详细介绍

文档处理流水线技能

概览

此技能可用于构建文档处理流水线——将多个操作(提取、转换、格式转换)串联起来,形成可复用的工作流,让数据在各个阶段之间流转。

使用方法

  1. 描述你想要完成的任务
  2. 提供所需的输入数据或文件
  3. 我会执行相应的操作

示例提示词:

  • “PDF → 提取文本 → 翻译 → 生成 DOCX”
  • “图像 → OCR → 总结 → 创建报告”
  • “Excel → 分析 → 生成图表 → 创建 PPT”
  • “多个输入 → 合并 → 格式化 → 输出”

领域知识

流水线架构
Stage 1      Stage 2      Stage 3      Stage 4
┌──────┐    ┌──────┐    ┌──────┐    ┌──────┐
│Extract│ → │Transform│ → │ AI   │ → │Output│
│ PDF  │    │  Data  │    │Analyze│   │ DOCX │
└──────┘    └──────┘    └──────┘    └──────┘
     │           │           │           │
     └───────────┴───────────┴───────────┘
                 Data Flow
流水线 DSL(领域特定语言)
# pipeline.yaml
name: contract-review-pipeline
description: Extract, analyze, and report on contracts

stages:
  - name: extract
    operation: pdf-extraction
    input: $input_file
    output: $extracted_text
    
  - name: analyze
    operation: ai-analyze
    input: $extracted_text
    prompt: "Review this contract for risks..."
    output: $analysis
    
  - name: report
    operation: docx-generation
    input: $analysis
    template: templates/review_report.docx
    output: $output_file
Python 实现
from typing import Callable, Any
from dataclasses import dataclass

@dataclass
class Stage:
    name: str
    operation: Callable
    
class Pipeline:
    def __init__(self, name: str):
        self.name = name
        self.stages: list[Stage] = []
    
    def add_stage(self, name: str, operation: Callable):
        self.stages.append(Stage(name, operation))
        return self  # Fluent API
    
    def run(self, input_data: Any) -> Any:
        data = input_data
        for stage in self.stages:
            print(f"Running stage: {stage.name}")
            data = stage.operation(data)
        return data

# Example usage
pipeline = Pipeline("contract-review")
pipeline.add_stage("extract", extract_pdf_text)
pipeline.add_stage("analyze", analyze_with_ai)
pipeline.add_stage("generate", create_docx_report)

result = pipeline.run("/path/to/contract.pdf")
进阶:条件流水线
class ConditionalPipeline(Pipeline):
    def add_conditional_stage(self, name: str, condition: Callable, 
                               if_true: Callable, if_false: Callable):
        def conditional_op(data):
            if condition(data):
                return if_true(data)
            return if_false(data)
        return self.add_stage(name, conditional_op)

# Usage
pipeline.add_conditional_stage(
    "ocr_if_needed",
    condition=lambda d: d.get("has_images"),
    if_true=run_ocr,
    if_false=lambda d: d
)

最佳实践

  1. 让各阶段各司其职(单一职责)
  2. 使用中间输出进行调试
  3. 实现阶段级错误处理
  4. 通过 YAML/JSON 配置流水线

安装

# Install required dependencies
pip install python-docx openpyxl python-pptx reportlab jinja2

资源

评论

支持 Markdown