Skip to main content

一个AI驱动的动态文档生成服务,可将文本转换为设计精美的图片。

Project description

DocGenius - AI驱动的动态文档生成服务

DocGenius 是一个基于模型上下文协议(MCP)的智能服务,能够接收用户的自然语言指令和文本内容,自主选择合适的文档模板,将文本内容渲染成设计精美的HTML,并输出为图片。

🚀 特性

  • 动态模板发现: AI能够自动扫描并发现可用的文档模板
  • 智能模板选择: 根据用户需求自动选择最合适的模板
  • 多种模板支持: 支持简历、知识卡片等多种文档类型
  • 高质量渲染: 使用Playwright进行精确的HTML到图片转换
  • 按模板分类存储: 自动按模板类型组织输出文件
  • 基于FastMCP: 使用现代化的MCP框架构建

📁 项目结构

card-creator-mcp/
├── templates/              # 模板文件目录
│   ├── resume.md          # 简历模板
│   └── knowledge_card.md  # 知识卡片模板
├── pic/                   # 输出图片目录(自动创建)
├── main_service.py        # 主服务文件
├── requirements.txt       # 项目依赖
└── README.md             # 项目文档

🛠️ 安装依赖

首先确保你已安装Python 3.10+,然后安装项目依赖:

pip install -r requirements.txt

安装Playwright浏览器:

playwright install chromium

🏃‍♂️ 运行服务

启动DocGenius MCP服务:

python main_service.py

或使用FastMCP CLI:

fastmcp run main_service.py

🎯 可用工具

1. list_available_templates()

列出所有可用的文档模板。

返回: 包含模板名称和描述的列表

2. get_template_details(template_name: str)

获取指定模板的详细信息,包括元数据和提示词。

参数:

  • template_name: 模板名称

返回: 包含模板详细信息的字典

3. create_image_from_html(html_content: str, template_name: str, file_name: str, width: int, height: int)

将HTML内容渲染为图片并保存。

参数:

  • html_content: HTML代码字符串
  • template_name: 使用的模板名称
  • file_name: 输出文件名(不含扩展名)
  • width: 图片宽度
  • height: 图片高度

返回: 任务执行结果字符串

📋 模板格式

模板文件采用Markdown格式,包含YAML Frontmatter:

---
description: "模板描述"
width: 800
height: 600
---
这里是提示词内容,使用 {user_text} 作为用户输入的占位符。

🔧 技术栈

  • FastMCP: MCP服务框架
  • Playwright: 无头浏览器自动化
  • python-frontmatter: YAML frontmatter解析
  • aiofiles: 异步文件操作

📝 使用示例

  1. 列出可用模板:

    templates = await client.call_tool("list_available_templates")
    
  2. 获取模板详情:

    details = await client.call_tool("get_template_details", {"template_name": "resume"})
    
  3. 生成图片:

    result = await client.call_tool("create_image_from_html", {
        "html_content": "<html>...</html>",
        "template_name": "resume",
        "file_name": "my_resume",
        "width": 827,
        "height": 1169
    })
    

🚧 开发状态

该项目目前处于1.1版本,包含核心功能实现。未来计划增加更多模板类型和自定义选项。

📄 许可证

本项目采用MIT许可证开源。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docgenius_service-2.0.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docgenius_service-2.0.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file docgenius_service-2.0.2.tar.gz.

File metadata

  • Download URL: docgenius_service-2.0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for docgenius_service-2.0.2.tar.gz
Algorithm Hash digest
SHA256 616c3454a9785ff5e92a136e3faada0aa2ecc6d7eecd6f284376dc935d8697c3
MD5 6fba807c82ae54197ed07b721ac1e1bb
BLAKE2b-256 c03657662669a7021a2dfca903bb8ae1ad158454b54a84819e69a52abd6ab897

See more details on using hashes here.

File details

Details for the file docgenius_service-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for docgenius_service-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 732cfed42b0e7df2b4d9b5e08670916d3fd303b0c5cbf1129ece8355f3c82f93
MD5 79aa82c10f02ad43929f2f6e9f569453
BLAKE2b-256 017e1aadbcdba2251ad60a90cb445a9a2d685a52484ec8792084d8a21afe5933

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page