Carlos-Projects/modelchain
GitHub: Carlos-Projects/modelchain
面向 AI 模型的 SBOM 生成器,提供来源追踪、完整性验证和合规报告功能。
Stars: 0 | Forks: 0
# ModelChain
[](https://github.com/Carlos-Projects/modelchain/releases)
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/MIT)
[](https://github.com/Carlos-Projects/modelchain/actions/workflows/ci.yml)
[](https://api.star-history.com/svg?repos=Carlos-Projects/modelchain&type=Date)
**面向 AI 模型的软件物料清单 (SBOM) 生成器**,具备来源追踪、密码学完整性验证以及合规性报告功能。
ModelChain 会创建 AI 模型供应链的完整来源记录:`基础模型 → 数据集 → 微调 → 适配器 → 部署`。它会验证每个步骤的完整性,并生成用于审计和合规的密码学清单。
## 功能
- **SBOM 生成** — 完整的模型 SBOM(基础模型、数据集、适配器、超参数、依赖项)
- **来源追踪** — 通过密码学验证追踪每个组件的来源
- **供应链审计** — 检测供应链中受损的组件
- **完整性清单** — 为每个组件生成 SHA-256 清单
- **依赖分析** — 分析模型依赖项中的已知漏洞
- **合规报告** — 欧盟《人工智能法案》(EU AI Act) 和 NIST AI RMF 报告
- **多格式输出** — CycloneDX、SPDX 2.3、ModelChain 原生格式、JSON、HTML
## 安装
```
git clone https://github.com/Carlos-Projects/modelchain.git
cd modelchain
pip install -e ".[dev]"
```
## 快速开始
### 基础 SBOM 生成
```
modelchain generate my-model 1.0.0 \
--type llm \
--base meta-llama/Meta-Llama-3-8B \
--framework transformers --framework-version 4.36.0 \
--author "Carlos-Projects" \
--description "My fine-tuned model"
```
### 包含数据集、适配器和依赖项
```
modelchain generate security-model 1.0.0 \
--type llm \
--base meta-llama/Meta-Llama-3-8B \
--dataset "security-instruct:2.1.0:huggingface:a1b2c3d4" \
--adapter "security-lora:LoRA:local:e5f6a1b2" \
--dependency "transformers:4.36.0:framework" \
--dependency "torch:2.1.0:framework" \
--output ./reports/sbom \
-v
```
### 验证完整性
```
modelchain verify manifest.json --base-path ./models
```
### 审计供应链
```
modelchain audit sbom.json
```
### 合规报告
```
modelchain report sbom.json --format console
modelchain report sbom.json --format json --output report.json
modelchain report sbom.json --format html --output report.html
```
## 输出格式
| 格式 | 命令 | 描述 |
|--------|---------|-------------|
| ModelChain | `--format modelchain` (默认) | 包含所有来源数据的原生 JSON 格式 |
| CycloneDX | `--format cyclonedx` | CycloneDX 1.6 AI SBOM 标准 |
| SPDX | `--format spdx` | SPDX 2.3 格式 |
## 合规框架
- **欧盟《人工智能法案》** — 检查透明度(第 13 条)、文档记录(第 11 条)、人工监督(第 14 条)、准确性/鲁棒性/网络安全(第 15 条)、数据治理(第 10 条)、风险管理(第 9 条)
- **NIST AI RMF 1.0** — 检查治理 (Govern)、映射 (Map)、度量 (Measure)、管理 (Manage) 类别
## 生态系统集成
| 项目 | 集成 |
|---------|-------------|
| [reverse-abliterate](https://github.com/Carlos-Projects/reverse-abliterate) | 共享完整性清单模式 (SHA-256),相同的 CLI 风格 |
| [mcp-taxonomy](https://github.com/Carlos-Projects/mcp-taxonomy) | MCP 安全分类法集成 |
| [MCPGuard](https://github.com/Carlos-Projects/mcpguard) | 兼容的策略生成 |
| [MCPscop](https://github.com/Carlos-Projects/mcpscope) | 可使用的报告格式 |
## 开发
```
# 运行测试
python -m pytest tests/ -v
# 带 coverage 运行
python -m pytest tests/ --cov=modelchain -v
# Lint
ruff check src/
# Type check
mypy src/modelchain/
```
## 项目结构
```
src/modelchain/
├── cli.py # Typer CLI (generate, verify, audit, report, sbom)
├── generator.py # Core SBOM generator
├── provenance/ # Provenance tracking & verification
├── sbom/ # SBOM builders (modelchain, cyclonedx, spdx)
├── supply_chain/ # Supply chain auditing & vulnerability correlation
├── integrity/ # SHA-256 manifests, fingerprints, diffs
├── compliance/ # EU AI Act & NIST AI RMF checkers
├── reporters/ # Console (Rich), JSON, HTML (Jinja2) output
└── utils/ # Cryptographic utilities
```
## 安全
发现漏洞?请参阅 [SECURITY.md](SECURITY.md)。
## 许可证
MIT 许可证 — 详情请参阅 [LICENSE](LICENSE)。
标签:AI模型, LLM防护, Python, SBOM生成, 安全规则引擎, 无后门, 逆向工具