Skip to content

Commit e7b6ffa

Browse files
authored
Bulid the mkdocs of Tutorial successfully (#563)
1 parent d736542 commit e7b6ffa

File tree

8 files changed

+208
-2
lines changed

8 files changed

+208
-2
lines changed

.github/workflows/deploy_doc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
run: |
2626
git submodule init LazyLLM-Env
2727
git submodule update LazyLLM-Env
28+
git submodule init Tutorial
29+
git submodule update Tutorial
2830
2931
- name: Set up python
3032
uses: actions/setup-python@v5
@@ -39,6 +41,8 @@ jobs:
3941
cp -r docs/assets docs/zh
4042
cp -r docs/assets docs/en
4143
python docs/add_docstrings.py
44+
python docs/link_assets.py
45+
python docs/ipynb2md.py
4246
python docs/gen_mkdocs_yaml.py
4347
4448
- name: Start MkDocs server

.readthedocs.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ build:
88
pre_build:
99
- pip install -r requirements.txt
1010
- pip install -r docs/requirements.txt
11+
- git submodule update --init --recursive
1112
- cp -r docs/assets docs/zh
1213
- cp -r docs/assets docs/en
1314
- python docs/add_docstrings.py
15+
- python docs/link_assets.py
16+
- python docs/ipynb2md.py 2>&1 | tee -a build.log
1417
- python docs/gen_mkdocs_yaml.py
1518

1619
python:
@@ -19,4 +22,3 @@ python:
1922

2023
mkdocs:
2124
configuration: mkdocs.yml
22-

Tutorial

Submodule Tutorial updated 436 files

docs/ipynb2md.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import nbformat
2+
import re
3+
import os
4+
import glob
5+
import logging
6+
from pathlib import Path
7+
8+
# Configure logging
9+
logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
10+
logger = logging.getLogger(__name__)
11+
12+
# Regex pattern to replace: <source src="./xxx"> → <source src="../xxx">
13+
VIDEO_SRC_PATTERN = re.compile(r'(<source\s+src=")\./([^"]+)(")')
14+
script_dir = os.path.dirname(os.path.abspath(__file__))
15+
16+
17+
def convert_ipynb_to_md(ipynb_path: str, output_dir: str):
18+
"""
19+
Convert a Jupyter notebook to Markdown, replacing video src paths.
20+
21+
Args:
22+
ipynb_path (str): Path to the input .ipynb file.
23+
output_dir (str): Directory to save the converted .md file.
24+
"""
25+
ipynb_path = Path(ipynb_path)
26+
notebook_name = ipynb_path.stem
27+
output_dir = Path(output_dir)
28+
md_path = output_dir / f"{notebook_name}.md"
29+
os.makedirs(md_path.parent, exist_ok=True)
30+
31+
with open(ipynb_path, "r", encoding="utf-8") as f:
32+
nb = nbformat.read(f, as_version=4)
33+
34+
md_lines = []
35+
36+
for cell in nb.cells:
37+
if cell.cell_type == "markdown":
38+
text = cell.source
39+
# Replace video source path from ./ to ../
40+
text = VIDEO_SRC_PATTERN.sub(r'\1../\2\3', text)
41+
md_lines.append(text)
42+
elif cell.cell_type == "code":
43+
if cell.get("source"):
44+
md_lines.append(f"```python\n{cell.source}\n```")
45+
46+
with open(md_path, "w", encoding="utf-8") as f:
47+
f.write("\n\n".join(md_lines))
48+
49+
# Try to get relative path for logging; fallback to filename if error occurs
50+
try:
51+
relative_md_path = md_path.relative_to(Path.cwd())
52+
except ValueError:
53+
relative_md_path = md_path.name
54+
55+
logger.info(f"✅ Converted: {ipynb_path.name}{relative_md_path}")
56+
57+
58+
if __name__ == "__main__":
59+
# Batch convert all notebooks matching the pattern
60+
input_files = glob.glob("Tutorial/rag/notebook/chapter*/*.ipynb", recursive=True)
61+
output_dir = os.path.join(script_dir, "zh/Tutorial")
62+
63+
for ipynb_file in input_files:
64+
convert_ipynb_to_md(ipynb_file, output_dir)

docs/link_assets.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import glob
3+
import shutil
4+
from pathlib import Path
5+
from itertools import chain
6+
7+
8+
def link_assets():
9+
"""
10+
Create symbolic links in docs/zh/Tutorial pointing to the actual
11+
{videos, images} directories found under Tutorial/rag/notebook/chapter*/.
12+
Each link will be named after the basename of the original directory.
13+
"""
14+
dest_dir = Path("docs/zh/Tutorial")
15+
dest_dir.mkdir(parents=True, exist_ok=True)
16+
17+
# Manually expand the {videos,images} part
18+
patterns = [
19+
"Tutorial/rag/notebook/chapter*/*_videos",
20+
"Tutorial/rag/notebook/chapter*/*_images",
21+
]
22+
paths = list(chain.from_iterable(glob.glob(p, recursive=True) for p in patterns))
23+
24+
for path_str in paths:
25+
path = Path(path_str)
26+
if not path.exists():
27+
continue
28+
29+
name = path.name
30+
target = path.resolve()
31+
link_path = dest_dir / name
32+
33+
try:
34+
if link_path.exists():
35+
if link_path.is_symlink() or link_path.is_file():
36+
link_path.unlink()
37+
elif link_path.is_dir():
38+
shutil.rmtree(link_path)
39+
os.symlink(target, link_path)
40+
print(f"✅ Linked {link_path}{target}")
41+
except Exception as e:
42+
print(f"❌ Failed to link {link_path}{target}: {e}")
43+
44+
45+
if __name__ == "__main__":
46+
link_assets()

docs/mkdocs.template.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ nav:
3232
- Flow: API Reference/flow.md
3333
- Module: API Reference/module.md
3434
- Tools: API Reference/tools.md
35+
- Tutorials:
36+
- Overview: Tutorial/index.md
37+
- Lesson 1: Tutorial/1.md
38+
- Lesson 2: Tutorial/2.md
39+
- Lesson 3: Tutorial/3.md
40+
- Lesson 4: Tutorial/4.md
41+
- Lesson 5: Tutorial/5.md
42+
- Lesson 6: Tutorial/6.md
43+
- Lesson 7: Tutorial/7.md
44+
- Lesson 8: Tutorial/8.md
45+
- Lesson 9: Tutorial/9.md
46+
- Lesson 10: Tutorial/10.md
47+
- Lesson 11: Tutorial/11.md
48+
- Lesson 12: Tutorial/12.md
49+
- Lesson 13: Tutorial/13.md
50+
- Lesson 14: Tutorial/14.md
51+
- Lesson 15: Tutorial/15.md
52+
- Lesson 16: Tutorial/16.md
53+
- Lesson 17: Tutorial/17.md
54+
- Lesson 18: Tutorial/18.md
55+
- Lesson 19: Tutorial/19.md
3556
theme:
3657
language: en
3758
name: material

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ redis
2929
funasr
3030
transformers
3131
ChatTTS
32+
nbformat

docs/zh/Tutorial/index.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# 教程概览
2+
3+
欢迎来到 LazyLLM 教程!
4+
5+
本教程旨在帮助你快速上手和深入了解 LazyLLM 的各项功能。
6+
7+
## 教程目录
8+
9+
- [第1讲 RAG原理解读:让检索增强生成不再是黑盒](1.md)
10+
透彻讲解 RAG(Retrieval-Augmented Generation)的原理与结构。
11+
12+
- [第2讲 10分钟上手一个最小可用RAG系统](2.md)
13+
零基础快速构建最小可运行的 RAG 系统。
14+
15+
- [第3讲 大模型怎么玩:用LazyLLM带你理解调用逻辑与Prompt魔法](3.md)
16+
深入理解大模型的调用过程与 Prompt 的组织方式。
17+
18+
- [第4讲 RAG项目工程化入门:从脚本走向模块化与可维护性](4.md)
19+
教你如何将 RAG 项目逐步工程化,提升可维护性。
20+
21+
- [第5讲 打造专属Reader组件:轻松解析HTML、PDF等复杂文档格式](5.md)
22+
自定义文档解析器,实现对多种文档格式的支持。
23+
24+
- [第6讲 检索更准:RAG召回效果优化的底层逻辑与技巧](6.md)
25+
学习影响召回效果的核心要素与优化策略。
26+
27+
- [第7讲 检索升级实践:亲手打造“更聪明”的文档理解系统!](7.md)
28+
实战提升系统对复杂文档的理解能力。
29+
30+
- [第8讲 不止是cosine!匹配策略决定你召回的质量](8.md)
31+
多种向量匹配策略的对比与应用分析。
32+
33+
- [第9讲 微调实践:让大模型和向量模型更懂你的领域](9.md)
34+
基于私有领域数据对 Embedding 与 LLM 进行微调。
35+
36+
- [第10讲 探索Deepseek:打造思维能力更强的RAG系统](10.md)
37+
集成 DeepSeek 等强模型提升多步推理能力。
38+
39+
- [第11讲 性能优化指南:从冷启动到响应加速你的RAG](11.md)
40+
全方位介绍 RAG 系统的启动与响应性能优化技巧。
41+
42+
- [第12讲 实践:用缓存、异步与向量引擎加速你的RAG](12.md)
43+
手把手教你使用缓存、异步处理、引擎插件等方式提速。
44+
45+
- [第13讲 RAG+多模态:图片、表格通吃的问答系统](13.md)
46+
构建支持图文混合理解的多模态 RAG 系统。
47+
48+
- [第14讲 实战:构建一个支持复杂学术论文问答的RAG系统](14.md)
49+
面向论文场景,搭建具备上下文、结构感知能力的系统。
50+
51+
- [第15讲 大视角问答:RAG如何支持跨文档、跨维度总结](15.md)
52+
实现多文档总结与维度整合型问答。
53+
54+
- [第16讲 实践:打造具备宏观问答与图表生成功能的论文问答的RAG系统](16.md)
55+
加入宏观总结与图表生成,提升问答系统交互质量。
56+
57+
- [第17讲 企业级RAG:权限、共享与内容安全的全链路方案](17.md)
58+
企业内部部署场景下的权限管理与安全设计实战。
59+
60+
- [第18讲 高阶RAG:Agentic RAG](18.md)
61+
探索 Agent + RAG 的融合方式,增强任务执行能力。
62+
63+
- [第19讲: RAG × 知识图谱:从关系结构中召回更准确的内容](19.md)
64+
打通结构化知识图谱与生成式问答系统的协同路径。
65+
66+
---
67+
68+
准备好开始探索了吗?点击任意一讲,即可深入学习 🚀

0 commit comments

Comments
 (0)