ai-openubmc-sr-builder
| Files | Last commit | Last update |
|---|---|---|
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 4 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 5 months ago |
openubmc-ai-compiler
openUBMC AI Semantic Compiler — 从硬件数据手册到产品 SR 的 AI 编译链。
快速开始
1. 安装
pip install -e .
2. 配置 API Key
cp .env.example .env
# 编辑 .env,填入你的 DashScope API Key
# 获取地址: https://dashscope.console.aliyun.com/apiKey
3. 准备输入数据
将你的硬件数据放入 datasets/datasheets/ 目录,创建 JSON 文件。
输入 JSON 格式如下(以 ADT7490 温度传感器为例):
{
"document_id": "your-chip-datasheet-id",
"sections": [
{
"section_id": "5.0",
"title": "Register Descriptions",
"page": "23",
"type": "register_table",
"content_summary": "Complete register map for XXX chip"
}
],
"tables": [
{
"table_id": "T5-1",
"page": "24",
"section_ref": "5.0",
"type": "register",
"raw_headers": ["Register Address", "Name", "Access", "Reset Value"],
"raw_rows": [
["0x00", "Status Register 1", "RO", "0x00"],
["0x25", "Configuration Register 1", "RW", "0x00"]
],
"confidence": 0.95
}
],
"register_candidates": [
{
"name": "Status Register 1",
"offset": "0x00",
"section_ref": "5.0",
"table_id": "T5-1",
"page": "24",
"confidence": 0.95
}
],
"unresolved": []
}
关键字段说明:
| 字段 | 说明 |
|---|---|
document_id |
芯片数据手册的唯一标识 |
sections |
文档章节信息,type 可选 register_table/bitfield_table/interface_def 等 |
tables |
从数据手册中提取的表格,raw_rows 是原始表格行 |
register_candidates |
初步识别的寄存器候选列表 |
unresolved |
无法解析的内容 |
4. 运行编译链
# 模拟运行(不调用模型,用 mock 数据验证流程)
python -m src.cli compile datasets/datasheets/mock_input.json --dry-run
# 真实模型运行(需要 API Key)
python -m src.cli compile datasets/datasheets/your_input.json
# 只跑指定阶段
python -m src.cli compile your_input.json --stages register_extract
# 查看模型路由和 Schema 配置
python -m src.cli info
5. 查看输出
输出自动保存到 outputs/ 目录:
outputs/
├── ir/ ← register_extract / semantic_infer 的中间结果
├── sr/ ← SR 配置(Phase 2 才会产出)
├── reports/ ← validate 的验证报告
└── tests/ ← testgen 的测试用例(Phase 2 才会产出)
编译链流程
结构化 JSON 输入(datasets/datasheets/*.json)
↓
register_extract — 寄存器抽取,提取寄存器定义和 bitfield
↓
semantic_infer — 语义推理,构建统一硬件语义图
↓
validate — 配置验证,检查冲突和一致性
↓
(Phase 2: topology_infer → sr_compile → repair → testgen)
Phase 1 当前状态
已实现的三个核心阶段:
| 阶段 | 模型 | temperature | 功能 |
|---|---|---|---|
| register_extract | GLM-5.1 (glm5_extract) | 0.1 | 从表格数据抽取寄存器定义 |
| semantic_infer | GLM-5.1 (glm5_semantic) | 0.2 | 构建硬件语义图(sensor/fan/gpio/mux 等) |
| validate | GLM-5.1 (glm5_validate) | 0.0 | 校验地址冲突/语义一致性 |
所有模型通过阿里云 DashScope 百炼平台调用(OpenAI 兼容接口)。
项目结构
openubmc-ai-compiler/
├── configs/ # 全局配置
│ ├── pipeline.yaml # 编译链总调度(阶段顺序/阈值/重试)
│ ├── model-routing.yaml # 模型路由(哪个阶段用哪个模型)
│ └── schema-routing.yaml # Schema 路由(每阶段的输入/输出校验)
│
├── schemas/ # JSON Schema 定义(5 个)
│ ├── hardware_ir.schema.json # 硬件 IR — register_extract 的输入/输出
│ ├── topology_ir.schema.json # 拓扑 IR — semantic_infer 的输出
│ ├── sr.schema.json # SR 配置 — sr_compile 的输出
│ ├── validation_report.schema.json # 验证报告 — validate 的输出
│ └── testcase.schema.json # 测试用例 — testgen 的输出
│
├── prompts/ # 各阶段 Prompt 模板(8 个)
│
├── skills/ # 各阶段 Skill 定义 + 示例 + eval
│
├── src/ # 运行时引擎
│ ├── cli.py # 命令行入口
│ ├── orchestrator.py # Pipeline 调度器
│ ├── model_router.py # 模型路由 + API 调用
│ ├── skill_runner.py # Skill 执行器
│ ├── prompt_loader.py # Prompt 加载 + {{VAR}} 注入
│ ├── schema_validator.py # JSON Schema 校验
│ └── io_store.py # 中间结果落盘
│
├── datasets/ # 数据集
│ ├── datasheets/ # ← 输入数据放在这里!
│ ├── mock_responses/ # dry-run 用的 mock 输出
│ └── ...
│
├── knowledge/ # 知识库(设备分类/协议/模式/故障模式)
├── outputs/ # ← 自动生成的输出在这里!
└── .env # API Key 配置(不要提交到 git)
输入数据录入指引
你要做的就是把芯片数据手册中的寄存器表整理成 JSON,放入 datasets/datasheets/ 目录。
整理步骤:
- 打开芯片 datasheet PDF
- 找到 Register Description 章节(通常是第 5 章或类似)
- 把寄存器表格转录为 JSON 的
tables.raw_rows格式 - 把接口信息(I2C 地址、SPI 参数等)记录到
register_candidates - 给
document_id赋一个唯一标识(如adi-adt7490-datasheet) - 保存为
datasets/datasheets/<芯片名>.json - 运行:
python -m src.cli compile datasets/datasheets/<芯片名>.json
关键规则
- 每一步输出必须通过 schema 校验
- 每一步必须输出
confidence,低于 0.7 不允许进入下一阶段 - 必须区分
fact(文档明确)和inference(推理得出) - 不确定的字段使用
FIXME标记,不要臆测 - 缺失关键字段时输出
ask_for_more_input
License
Internal use only.