docs-auditor:基于 LLM API 的技术文档审计 CLI 工具

可用于自动化审计 Markdown 技术文档,支持自然语言规则批量检查,提供多维度报告。具备规则优先级过滤、多种审计模式、多模型支持及智能API速率限制处理等功能。【此简介由AI生成】

Branch1Tags0
FilesLast commitLast update
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago

Doc Auditor

A Python CLI tool for automated technical document auditing using LLM APIs.

Features

  • Support natural language rules (CSV/Excel/Markdown input)
  • Batch audit Markdown documents
  • Rule priority support (高/中/低) with automatic sorting and filtering
  • Rule applicability filtering (API参考/开发指南/全部)
  • Prompt URL support: Fetch additional prompt content from remote URLs
  • Multiple audit modes:
    • Single rule × Single document
    • Single rule × Multiple documents
    • Multiple rules × Single document
    • Multiple rules × Multiple documents
  • Multi-model support (OpenAI, Anthropic, Zhipu AI GLM)
  • Intelligent API rate limit handling with exponential backoff
  • Multi-dimensional reporting:
    • By rule dimension
    • By document dimension
    • Summary report
  • Report formats: Markdown + Excel
  • Real-time progress tracking with detailed information
  • Automatic retry mechanism for API failures
  • Configuration via .env file

Installation

pip install -r requirements.txt

Configuration

Create a .env file:

MODEL_PROVIDER=openai
API_KEY=your_api_key_here
MODEL_NAME=gpt-4
BASE_URL=https://api.openai.com/v1
OUTPUT_DIR=./reports
MAX_RETRIES=3
TIMEOUT=30
MAX_CONCURRENT_API_CALLS=10

OpenAI Configuration

MODEL_PROVIDER=openai
API_KEY=sk-xxxxx
MODEL_NAME=gpt-4
BASE_URL=https://api.openai.com/v1

Zhipu AI (GLM) Configuration

MODEL_PROVIDER=openai
API_KEY=your_zhipu_api_key
MODEL_NAME=GLM-4.7
BASE_URL=https://open.bigmodel.cn/api/coding/paas/v4
API_ENDPOINT=/chat/completions
TIMEOUT=300
MAX_CONCURRENT_API_CALLS=3

Note: Zhipu AI has rate limits. Recommended settings:

  • MAX_CONCURRENT_API_CALLS=3 (or lower)
  • Use --priority to run rules in batches
  • See API Rate Limit Handling section for details

Volcengine Configuration

MODEL_PROVIDER=openai
API_KEY=your_api_key
MODEL_NAME=ep-xxxxx
BASE_URL=https://ark.cn-beijing.volces.com/api/v3

Usage

Basic usage (multiple rules × multiple documents)

# Using CSV rules
python main.py --rules rules.csv --docs ./docs

# Using Markdown rules directory
python main.py --rules ./rules-md --docs ./

# Using single Markdown rule
python main.py --rules example-rules-md/RULE-04-01.md --docs ./docs

Filter by specific rule IDs (NEW)

Run audit with specific rule IDs:

# Single rule ID
python main.py --rules rules.csv --docs ./docs --rule-ids "rule-001"

# Multiple rule IDs (comma-separated)
python main.py --rules rules.csv --docs ./docs --rule-ids "rule-001,rule-002,rule-003"

Filter by priority (NEW)

Run rules with specific priority levels:

# Run only high priority rules
python main.py --rules rules.csv --docs ./docs --priority 高

# Run high and medium priority rules
python main.py --rules rules.csv --docs ./docs --priority 高,中

# Run all rules (automatically sorted by priority: 高 > 中 > 低)
python main.py --rules rules.csv --docs ./docs

Priority-based batch execution (recommended for rate-limited APIs):

# Batch 1: High priority (fewer rules, faster)
python main.py --rules rules.csv --docs ./docs --priority 高 --max-concurrent 2

# Batch 2: Medium priority
python main.py --rules rules.csv --docs ./docs --priority 中 --max-concurrent 3

# Batch 3: Low priority
python main.py --rules rules.csv --docs ./docs --priority 低 --max-concurrent 5

Options

--rules PATH                       # Rules file or directory (required)
--docs PATH                        # Document or directory (required)
--rule-ids IDS                     # Filter by specific rule IDs, comma-separated (NEW)
--document-path PATH               # Filter by specific document path
--priority PRIORITY                # Filter by priority (高/中/低), comma-separated for multiple (NEW)
--model-provider openai|anthropic  # Model provider (default: openai)
--model-name MODEL                 # Model name (default: gpt-4)
--api-key KEY                      # API key (overrides env)
--base-url URL                     # Base URL for API (overrides default)
--api-endpoint PATH               # API endpoint (overrides default)
--output-dir DIR                   # Output directory (default: ./reports)
--report-dimensions rule,document,summary  # Report dimensions
--max-concurrent N                 # Max concurrent API calls (default: 10, recommended: 3 for Zhipu AI)
--verbose                          # Verbose output
--show-details                     # Show prompt and model response details

Progress Display

The tool shows real-time progress with the following information:

[RULE-04-01] test-doc.md: 100%|████| 1/1 [00:08<00:00, 8.38s/doc, tokens: 1496, issues: 0 | in: You are a technical document auditor. Ch... | out: ```json {     "issues": [] } ```]
  • Progress bar with percentage and completion status
  • Current rule ID and document name
  • Tokens used and issues found
  • Input/output content preview (first 40 characters)

Error Handling

The tool includes automatic retry mechanism for API failures:

  • Timeout errors: Automatically retry with exponential backoff
  • Rate limiting (429): Wait and retry automatically (4s → 8s → 16s)
  • Server errors (5xx): Automatically retry
  • Network errors: Automatically retry
  • JSON parsing errors: Log error but continue processing

API Rate Limit Handling

When using rate-limited APIs (especially Zhipu AI GLM-4.7), you may encounter 429 errors. Here are solutions:

# Use lower concurrency
python main.py --rules rules.csv --docs ./docs --max-concurrent 2

Recommended values:

  • Zhipu AI: --max-concurrent 2 or 3
  • OpenAI: --max-concurrent 5 to 10

Solution 2: Priority-based Batching (Best Practice)

Run rules in batches by priority level:

# Run high priority rules (fewer rules, faster)
python main.py --rules rules.csv --docs ./docs --priority 高 --max-concurrent 2

# Run medium priority rules
python main.py --rules rules.csv --docs ./docs --priority 中 --max-concurrent 3

# Run low priority rules
python main.py --rules rules.csv --docs ./docs --priority 低 --max-concurrent 5

Solution 3: Process Documents in Batches

# Process subdirectories separately
python main.py --rules rules.csv --docs ./docs/dev-guide/ui --max-concurrent 3
python main.py --rules rules.csv --docs ./docs/api/reference --max-concurrent 3

Retry Mechanism

The tool automatically implements exponential backoff for 429 errors:

  • 1st retry: Wait 4 seconds
  • 2nd retry: Wait 8 seconds
  • 3rd retry: Wait 16 seconds
  • Maximum wait: 30 seconds

What to Do When You See 429 Errors

  1. Wait 1-2 minutes - Let the rate limit window pass
  2. Reduce concurrency - Use --max-concurrent 2
  3. Use priority batching - Run --priority 高, then 中, then 低
  4. Check your quota - Verify API quota in your provider's dashboard

Rules File Format

CSV/Excel Format

Supports two CSV formats:

Standard Format

CSV or Excel with columns:

  • rule_id: Unique rule identifier
  • description: Natural language rule description
  • severity: error, warning, or info (optional)
  • category: Rule category (optional)
  • tags: Comma-separated tags (optional)

Example CSV:

rule_id,description,severity,category,tags
rule-001,必须包含示例代码,error,代码质量,示例
rule-002,API描述必须完整,warning,文档规范,API

Extended Format

CSV or Excel with columns:

  • 编号: Rule number
  • 适用: Rule scope (全部/API参考/开发指南)
  • 优先级: Priority level (高/中/低)
  • 分类: Rule category
  • 细分: Rule subcategory
  • 规则: Rule content
  • 详细描述: Detailed rule description (optional)
  • 提示词: Prompt URL (optional, for fetching additional prompt content)

Rule name is generated by concatenating "分类+细分", and rule content is generated by concatenating "规则" and "详细描述".

Example CSV:

编号,适用,优先级,分类,细分,规则,详细描述,提示词
001,全部,高,文档规范,命名规范,命名必须清晰,所有文档命名必须清晰易懂,
002,API参考,中,API规范,参数说明,API参数必须有类型说明,所有API参数必须包含类型信息,https://gitcode.com/xxx/prompt.md
003,开发指南,低,代码质量,示例,代码必须有注释,所有代码示例必须包含注释,

Rule Applicability:

  • 适用=全部: Rule applies to all documents
  • 适用=API参考: Rule applies only to documents in docs/api/ directory
  • 适用=开发指南: Rule applies only to documents in docs/dev-guide/ directory

Rule Priority:

  • 优先级=高: High priority - critical rules
  • 优先级=中: Medium priority - important rules
  • 优先级=低: Low priority - nice-to-have rules
  • Rules are automatically sorted by priority (高 > 中 > 低) when --priority is not specified

Prompt URL:

  • The 提示词 column can contain markdown file links from platforms like GitCode
  • The system automatically fetches the link content and appends it to the prompt
  • Link format example: https://gitcode.com/circlezlo/docs-prompt/blob/master/inconsistent.md
  • The system automatically converts to raw URL to fetch markdown raw content

Markdown Format

One rule per Markdown file with YAML frontmatter:

---
severity: error
category: 代码质量
tags: 示例
---

文档必须包含代码示例,以帮助用户理解如何使用功能。每个主要功能点都应该有相应的代码示例。

The filename (without .md extension) becomes the rule ID.

Output

Reports are generated in the output directory:

reports/
├── by-rule/
│   ├── rule-001-must-include-examples.md
│   └── rule-002-api-description-complete.md
├── by-document/
│   ├── README.md
│   └── API-Guide.md
├── summary.md
├── realtime_issues.md          # Real-time issue tracking
├── report.xlsx                 # Excel report with multiple sheets
└── details/                    # Created when using --show-details
    ├── rule-001_README.md.txt
    └── rule-002_API-Guide.md.txt

Report Content

All reports include the following columns:

  • 规则编号 (Rule ID)
  • 规则名称 (Rule Name)
  • 优先级 (Priority: 高/中/低)
  • 文档名称 (Document Name)
  • 文档地址 (Document URL - clickable link to remote repository with line number)
  • 问题位置 (Issue Location)
  • 严重程度 (Severity)
  • 问题描述 (Issue Description)
  • 修改建议 (Suggestion)

When using --show-details, complete prompts and model responses are saved to the details/ directory for debugging purposes.

Architecture

The system is designed with modularity in mind, making it easy to extend to a web application:

  • Core auditing logic is independent of CLI
  • Model adapters follow a common interface
  • Report generators are pluggable
  • Configuration is centralized

License

MIT

Introduction

可用于自动化审计 Markdown 技术文档,支持自然语言规则批量检查,提供多维度报告。具备规则优先级过滤、多种审计模式、多模型支持及智能API速率限制处理等功能。【此简介由AI生成】

Customize your domain