基于 Neo4j 图谱和 LangGraph 工作流的自动化项目文档生成工具。
自动生成以下类型的文档:
- ✅ 系统架构文档 - 模块分析、依赖关系、接口设计等
pip install -r requirements.txt复制环境变量模板并填入配置:
cp env.template .env
nano .env # 填入 Neo4j 和 OpenAI 配置python test_interfaces.pypython main.py生成的文档位于 output/system_architecture.md
wiki_generator/
├── interfaces/ # 数据接口层
│ ├── neo4j_interface.py # Neo4j 查询接口
│ └── llm_interface.py # LLM 调用接口
├── graph/ # LangGraph 工作流
│ └── system_arch_graph.py # 系统架构文档生成工作流
├── prompts/ # 提示词模板
│ └── system_arch_prompts.py
├── main.py # 程序入口
├── test_interfaces.py # 测试脚本
├── output/ # 输出目录
└── README.md # 本文件
- Neo4jInterface: 封装所有 Cypher 查询,提供模块、依赖、类层次等数据
- LLMInterface: 封装 LLM 调用,提供模板调用、总结、润色等功能
- SystemArchGraph: 7 个节点的完整工作流
- 加载数据
- 分析模块
- 分析依赖
- 分析接口
- 分析类层次
- 分析核心类
- 组装文档
所有 LLM 提示词模板的集中管理,便于优化和调整。
from interfaces import Neo4jInterface, LLMInterface
# Neo4j 查询
with Neo4jInterface() as neo4j:
blocks = neo4j.get_all_blocks()
print(f"找到 {len(blocks)} 个模块")
# LLM 调用
llm = LLMInterface()
summary = llm.summarize_text("长文本...", max_length=200)from graph import SystemArchGraph
graph = SystemArchGraph()
result = graph.run(output_path="my_doc.md")必需配置(在 .env 文件中):
NEO4J_URI=bolt://localhost:7687 # Neo4j 连接地址
NEO4J_USER=neo4j # Neo4j 用户名
NEO4J_PASSWORD=password # Neo4j 密码
OPENAI_API_KEY=sk-xxx # OpenAI API Key可选配置:
LLM_MODEL=gpt-4-turbo-preview # LLM 模型
LLM_TEMPERATURE=0.3 # 温度参数 (0.0-1.0)
SOURCE_PATH=/path/to/source # 源码路径(未来功能)Block- 模块(功能聚类)File- 文件Class- 类Interface- 接口Enum- 枚举Method- 方法Field- 字段Annotation- 注解Record- 记录
block f2c file- Block 与 File 的映射file declares class/interface/enum...- 文件声明class extends class- 继承class implements interface- 实现method calls method- 方法调用method uses class- 方法使用- 等等...
name(必需) - 节点名称semantic_explanation(推荐) - 语义解释
- 在
graph/下创建新工作流,如api_doc_graph.py - 在
prompts/下创建对应提示词,如api_doc_prompts.py - 在
main.py中添加调用选项
编辑 prompts/system_arch_prompts.py,调整各分析模板的内容和格式。
编辑 interfaces/neo4j_interface.py,添加或优化 Cypher 查询。
- 首次运行建议先用小型项目测试
- LLM API 调用会产生费用,请注意成本
- 确保 Neo4j 图谱数据完整且准确
- 大型项目建议调整查询限制参数
MIT License