Feature Description
The proposed feature aims to automate the process of creating PowerPoint presentations using AI. This feature includes generating a structured outline and detailed content for each slide based on a given topic. The feature integrates with the MetaGPT framework and leverages asynchronous operations to enhance efficiency. The generated presentations are saved as PPT files, ready for use in professional settings.
Your Feature
The implementation of this feature involves the creation of two primary actions within the MetaGPT framework: CreatePPTOutline and CreatePPTContent.
CODE:
from datetime import datetime
from typing import Dict
import os
from pptx import Presentation
import json
import asyncio
from metagpt.logs import logger
from metagpt.roles.role import Role,RoleReactMode
from metagpt.schema import Message
from pptx.util import Pt
from metagpt.utils.file import File
from metagpt.actions import Action
from metagpt.utils.common import OutputParser
class CreatePPTOutline(Action):
name: str = "CreatePPTOutline",
language:str = "chinese"
async def run(self, topic: str, *args, **kwargs) -> Dict:
COMMON_PROMPT = """
You are now a seasoned professional in creating PowerPoint presentations.
We need you to create an outline for a PPT with the topic "{topic}".
"""
OUTLINE_PROMPT = COMMON_PROMPT + """
Please provide a specific outline for this PPT, strictly following the following requirements:
1. The output must be strictly in the specified language, {language}.
2. Answer strictly in the dictionary format like {{"title": "xxx", "outline": [{{"slide 1": ["point 1", "point 2"]}}, {{"slide 2": ["point 3", "point 4"]}}]}}.
3. The outline should be as specific and sufficient as possible, with a main slide and sub-points. The sub-points should use {language}.
4. Do not have extra spaces or line breaks.
5. Each slide title and point must have practical significance.
"""
prompt = OUTLINE_PROMPT.format(topic=topic, language=self.language)
resp = await self._aask(prompt=prompt)
# 替换全角逗号为半角逗号
resp = resp.replace(',', ',')
return OutputParser.extract_struct(resp, "dict")
async def run(self, topic: str, *args, **kwargs) -> str:
COMMON_PROMPT = """
You are now a seasoned professional in creating PowerPoint presentations.
We need you to create content for a PPT with the topic "{topic}".
"""
output_format = json.dumps({
"title": "example title",
"pages": [
{
"title": "title for page 1",
"content": [
{
"title": "title for paragraph 1",
"description": ["detail for paragraph 1"],
},
{
"title": "title for paragraph 2",
"description": ["detail for paragraph 2"],
},
],
}
],
}, ensure_ascii=False)
CONTENT_PROMPT = COMMON_PROMPT+"""
Now I will give you the outline for the topic.
Please output the detailed content for each slide, ensuring it is well-structured and engaging.
The outline for the topic is as follows:
{outline}
Strictly limit output according to the following requirements:
1. Follow standard presentation structure and formatting.
2. Each slide should have a title and detailed content with bullet points or numbered lists.
3. The output must be strictly in the specified language,{language}.
4. Do not have redundant output, including concluding remarks.
5. Strict requirement not to output the topic "{topic}".
6. According to this JSON format, the output {output_format} can only return JSON, and the JSON should not be wrapped with ```
"""
prompt = CONTENT_PROMPT.format(
topic=topic, language=self.language, outline=self.outline,output_format=output_format)
return await self._aask(prompt=prompt)
Feature Description The proposed feature aims to automate the process of creating PowerPoint presentations using AI. This feature includes generating a structured outline and detailed content for each slide based on a given topic. The feature integrates with the MetaGPT framework and leverages asynchronous operations to enhance efficiency. The generated presentations are saved as PPT files, ready for use in professional settings.
Your Feature The implementation of this feature involves the creation of two primary actions within the MetaGPT framework: CreatePPTOutline and CreatePPTContent.
CODE: from datetime import datetime from typing import Dict import os from pptx import Presentation import json import asyncio from metagpt.logs import logger from metagpt.roles.role import Role,RoleReactMode from metagpt.schema import Message from pptx.util import Pt from metagpt.utils.file import File from metagpt.actions import Action from metagpt.utils.common import OutputParser
class CreatePPTOutline(Action): name: str = "CreatePPTOutline", language:str = "chinese"
class CreatePPTContent(Action): name: str = "CreatePPTContent" outline: str = "" language: str = "chinese"
class PPTDesigner(Role):
async def main(): msg = "华为公司" role = PPTDesigner() logger.info(msg) result = await role.run(msg) logger.info(result)
asyncio.run(main())