-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from DjangoPeng/v0.7
[v0.7]: Add unit tests, Docker integration, and update documentation @DjangoPeng
- Loading branch information
Showing
13 changed files
with
627 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,3 +170,4 @@ jupyter/*.pptx | |
.gradio/* | ||
nohup.out | ||
images/* | ||
test_results.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 使用 Python 3.10 slim 作为基础镜像 | ||
FROM python:3.10-slim | ||
|
||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 复制并安装项目依赖 | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# 复制项目文件到容器 | ||
COPY . . | ||
|
||
# 赋予验证脚本执行权限 | ||
RUN chmod +x validate_tests.sh | ||
|
||
# 设置环境变量,以便在运行时可以传入实际的 API Key | ||
ENV LANGCHAIN_API_KEY=${LANGCHAIN_API_KEY} | ||
ENV OPENAI_API_KEY=${OPENAI_API_KEY} | ||
|
||
# 在构建过程中运行单元测试 | ||
RUN ./validate_tests.sh | ||
|
||
# 设置容器的入口点,默认运行 ChatPPT Gradio Server | ||
CMD ["python", "src/gradio_server.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
# 获取当前的 Git 分支名称 | ||
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
# 如果需要,可以处理分支名称,例如替换无效字符 | ||
BRANCH_NAME=${BRANCH_NAME//\//-} | ||
|
||
# 使用 Git 分支名称作为 Docker 镜像的标签 | ||
IMAGE_TAG="chatppt:${BRANCH_NAME}" | ||
|
||
# 构建 Docker 镜像 | ||
docker build -t $IMAGE_TAG . | ||
|
||
# 输出构建结果 | ||
echo "Docker 镜像已构建并打上标签: $IMAGE_TAG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import unittest | ||
import os | ||
import sys | ||
|
||
# 添加 src 目录到模块搜索路径,以便可以导入 src 目录中的模块 | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) | ||
|
||
from data_structures import PowerPoint, Slide, SlideContent | ||
|
||
class TestDataStructures(unittest.TestCase): | ||
""" | ||
测试 PowerPoint、Slide、SlideContent 数据类,验证数据结构的正确性。 | ||
""" | ||
|
||
def test_slide_content(self): | ||
slide_content = SlideContent(title="Test Slide", bullet_points=[{'text': "Bullet 1", 'level': 0}], image_path="images/test.png") | ||
self.assertEqual(slide_content.title, "Test Slide") | ||
self.assertEqual(slide_content.bullet_points, [{'text': "Bullet 1", 'level': 0}]) | ||
self.assertEqual(slide_content.image_path, "images/test.png") | ||
|
||
def test_slide(self): | ||
slide_content = SlideContent(title="Slide with Layout") | ||
slide = Slide(layout_id=2, layout_name="Title, Content 0", content=slide_content) | ||
self.assertEqual(slide.layout_id, 2) | ||
self.assertEqual(slide.layout_name, "Title, Content 0") | ||
self.assertEqual(slide.content.title, "Slide with Layout") | ||
|
||
def test_powerpoint(self): | ||
slide_content1 = SlideContent(title="Slide 1") | ||
slide_content2 = SlideContent(title="Slide 2") | ||
slide1 = Slide(layout_id=1, layout_name="Title 1", content=slide_content1) | ||
slide2 = Slide(layout_id=2, layout_name="Title, Content 0", content=slide_content2) | ||
ppt = PowerPoint(title="Test Presentation", slides=[slide1, slide2]) | ||
|
||
self.assertEqual(ppt.title, "Test Presentation") | ||
self.assertEqual(len(ppt.slides), 2) | ||
self.assertEqual(ppt.slides[0].content.title, "Slide 1") | ||
self.assertEqual(ppt.slides[1].content.title, "Slide 2") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import unittest | ||
import os | ||
import sys | ||
|
||
# 添加 src 目录到模块搜索路径,以便可以导入 src 目录中的模块 | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) | ||
|
||
from docx_parser import generate_markdown_from_docx | ||
|
||
class TestGenerateMarkdownFromDocx(unittest.TestCase): | ||
""" | ||
测试从 docx 文件生成 Markdown 格式内容的功能。 | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
在每个测试方法执行前运行。用于准备测试所需的文件和目录。 | ||
""" | ||
# 定义测试 docx 文件的路径 | ||
self.test_docx_filename = 'inputs/docx/multimodal_llm_overview.docx' | ||
|
||
# 生成 Markdown 内容 | ||
self.generated_markdown = generate_markdown_from_docx(self.test_docx_filename) | ||
|
||
def test_generated_markdown_content(self): | ||
""" | ||
测试生成的 Markdown 内容是否符合预期。 | ||
""" | ||
# 期望的 Markdown 输出内容 | ||
expected_markdown = """ | ||
# 多模态大模型概述 | ||
多模态大模型是指能够处理多种数据模态(如文本、图像、音频等)的人工智能模型。它们在自然语言处理、计算机视觉等领域有广泛的应用。 | ||
## 1. 多模态大模型的特点 | ||
- 支持多种数据类型: | ||
- 跨模态学习能力: | ||
- 广泛的应用场景: | ||
### 1.1 支持多种数据类型 | ||
多模态大模型能够同时处理文本、图像、音频等多种类型的数据,实现数据的融合。 | ||
## 2. 多模态模型架构 | ||
以下是多模态模型的典型架构示意图: | ||
![图片1](images/multimodal_llm_overview/1.png) | ||
TransFormer 架构图: | ||
![图片2](images/multimodal_llm_overview/2.png) | ||
### 2.1 模态融合技术 | ||
通过模态融合,可以提升模型对复杂数据的理解能力。 | ||
关键技术:注意力机制、Transformer架构等。 | ||
- 应用领域: | ||
- 自然语言处理: | ||
- 机器翻译、文本生成等。 | ||
- 计算机视觉: | ||
- 图像识别、目标检测等。 | ||
## 3. 未来展望 | ||
多模态大模型将在人工智能领域持续发挥重要作用,推动技术创新。 | ||
""" | ||
|
||
# 比较生成的 Markdown 内容与预期内容 | ||
self.assertEqual(self.generated_markdown.strip(), expected_markdown.strip(), "生成的 Markdown 内容与预期不匹配") | ||
|
||
def tearDown(self): | ||
""" | ||
在每个测试方法执行后运行。用于清理测试产生的文件和目录。 | ||
""" | ||
# 获取图像目录路径 | ||
images_dir = 'images/multimodal_llm_overview' | ||
# 删除生成的图像文件和目录 | ||
if os.path.exists(images_dir): | ||
for filename in os.listdir(images_dir): | ||
file_path = os.path.join(images_dir, filename) | ||
if os.path.isfile(file_path): | ||
os.unlink(file_path) # 删除文件 | ||
os.rmdir(images_dir) # 删除目录 | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.