Skip to content

add PPTMaker #1830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

add PPTMaker #1830

wants to merge 4 commits into from

Conversation

Rubbisheep
Copy link

功能概述

添加了新的 PPTMaker 角色,能够生成基于 LaTeX Beamer 的演示文稿。PPTMaker 通过协调 LatexGeneratorActionValidatorAction 两个 Action,实现了一个迭代式生成-验证流程,能够逐步构建并优化 LaTeX 演示文稿内容。

主要特性

  • 基于 LaTeX Beamer 的演示文稿:生成包含完整结构、数学公式和适当格式的专业演示文稿
  • 迭代优化:通过生成和验证的循环过程,持续改进内容质量
  • 自动验证:验证器能判断内容是否满足要求,并提供改进建议
  • 提前终止:当内容质量达到要求时,自动结束生成过程
  • 文件导出:自动将生成的 LaTeX 内容保存到工作区目录

实现细节

  • 新增两个 Action 类:LatexGeneratorActionValidatorAction
  • 创建了 PPTMaker 角色类,继承自 RoleZero
  • 实现了固定的工具执行序列和最大步骤限制
  • 包含文件保存功能,可将结果导出为 .md 文件
  • 使用 LLM 的相关提示词已添加到 metagpt.prompts.PPTmaker 模块

使用示例

from metagpt.roles.PPTmaker import PPTMaker
from metagpt.schema import Message

async def create_presentation():
    maker = PPTMaker()
    prompt = """
    1. Lecture slide:
    I am a lecturer. I am teaching the machine learning coure for research students. Please generate latex code for lecture slide for different reinforcement learning algorithms.
    Note that:
    1). Note that the lecture duration is 2 hour, so we need to generate 30 pages.
    2). for each reinforcement learning algorithms, the slide should include motivation, problem and intuitive solution and detailed math equations.
    3). Please make sure the the lecture have a good self-contain.
    """
    response = await maker.run(Message(content=prompt))
    print(response) 

计划改进

  • 添加更多格式化选项以支持不同的演示风格
  • 添加更多自定义选项,如颜色主题、布局等
  • 增加latex渲染引擎直接输出pdf
  • 在验证阶段启用视觉验证,避免生成乱码或格式错误

相关文件

  • metagpt/roles/PPTmaker.py - 主要实现
  • metagpt/prompts/PPTmaker.py - 提示词定义


self.curr_step += 1
return Message(content=self.optimized_result or message_content, role=self.profile, cause_by=tool_class)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest making the code more concise and maintainable by simplifying its structure and improving readability. For example:

async def react(self) -> Message:
        """Process current state, decide next action, execute and return a Message."""
        available_tools = {
            "latexgenerator": (LatexGeneratorAction, True),  # (工具类, 是否保存结果)
            "validator": (ValidatorAction, False)
        }
        
        tool_name = list(available_tools.keys())[self.curr_step % len(available_tools)]
        tool_class, save_result = available_tools[tool_name]
        tool = tool_class()

        try:
            result = await tool.run(
                request=self.rc.history[0].content,
                history=self.rc.history
            )
            
            if save_result:
                self.optimized_result = result
            
            self.rc.memory.add(result)
            
            if isinstance(tool, ValidatorAction) and "No further feedback" in result:
                self.is_completed = True
                return Message(content=self.optimized_result, role=self.profile, cause_by=tool_class)

        except Exception as e:
            logger.error(f"Error executing {tool_name}: {e}")

        self.curr_step += 1
        return Message(
            content=self.optimized_result or f"Step {self.curr_step}/{self.max_steps}: {tool_name}",
            role=self.profile,
            cause_by=tool_class
        )```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants