commit ee323dda781d4540f02133397a93bc34094c45c7 Author: zlei9 Date: Sun Mar 29 08:34:26 2026 +0800 Initial commit with translated description diff --git a/SKILL.md b/SKILL.md new file mode 100644 index 0000000..52e704c --- /dev/null +++ b/SKILL.md @@ -0,0 +1,83 @@ +--- +name: ai-ppt-generate +description: "百度提供的智能PPT生成工具。根据用户给定的主题或问题智能生成PPT的工具。用户可以选择PPT主题、模板,甚至自定义自己的模板。还提供图片或资源文件(如pdf、word、txt等)。提供最终生成的PPT文件的下载地址。" +metadata: { "openclaw": { "emoji": "📑", "requires": { "bins": ["python"] } } } +--- + +# AI PPT Generation + +This skill allows OpenClaw agents to generate ppt file, Based solely on the theme provided by the user, if possible, pictures or resource files can be provided, this tool can help generate perfect PPT files. + +## Setup + +1. **API Key:** Ensure the BAIDU_API_KEY environment variable is set with your valid API key. +2. **Environment:** The API key should be available in the runtime environment. + +## API table +| name | path | description | +|------------|---------------------------------|---------------------------------------| +|PPTThemeQuery|/v2/tools/ai_ppt/get_ppt_theme|Query the built-in list of PPT themes and templates| +|PPTOutlineGenerate| /v2/tools/ai_ppt/generate_outline |Generate a PPT outline based on the provided theme, template ID, style ID, etc| +|PPTGenerate| /v2/tools/ai_ppt/generate_ppt_by_outline |Generate a PPT file url based on the provided ppt outline| + + +## Workflow + +1. The PPTThemeQuery API executes the Python script located at `scripts/ppt_theme_list.py` +2. The PPTOutlineGenerate API executes the Python script located at `scripts/ppt_outline_generate.py` +3. The PPTGenerate API executes the Python script located at `scripts/ppt_generate.py` +4. The first step is for the user to query the PPT style query interface(PPTThemeQuery) to obtain the style ID and template ID +5. The second step is to use the style ID and template ID queried in the first step as parameters for generating the PPT outline and call the PPT outline generation API(PPTOutlineGenerate) to generate the outline (this API is a sse streaming return. This step depends on the first step. If the first step fails, the request can be terminated). +6. The third step is to request the PPT intelligent generation API(PPTGenerate) based on the outline generated in the second step. Eventually, a PPT file is generated (the request parameter outline is returned by the outline generation interface, aggregating the sse streaming return result as the input parameter. Meanwhile, users can edit and modify the outline, but the modified outline must be in markdown format). Otherwise, a failure may occur. This step strictly depends on the second step. If the second step fails, the request can be terminated. + +## APIS + +### PPTThemeQuery API + +#### Parameters + +no parameters + +#### Example Usage +```bash +BAIDU_API_KEY=xxx python3 scripts/ppt_theme_list.py +``` + +### PPTOutlineGenerate API + +#### Parameters + +- `query`: ppt title or user query(required) +- `resource_url`: the url of the resource file, such as pdf, word, txt, etc. +- `page_range`: the page range of the ppt file, just include enumerations, 1-10、11-20、21-30、31-40、40+ +- `layout`: the layout of the ppt file, optional values: 1,2 (1: Minimalist mode, 2: Professional Mode) +- `language_option`: the language option of the ppt file, optional values: zh, en (zh: Chinese, en: English) +- `gen_mode`: the generation mode of the ppt, optional values: 1,2 (1: Intelligent touch-ups, 2: Creative Mode) + + +#### Example Usage +```bash +BAIDU_API_KEY=xxx python3 scripts/ppt_outline_generate.py --query "generate a ppt about the future of AI" +``` + +### PPTGenerate API + +#### Parameters + +- `query_id`: query id from PPTOutlineGenerate API return(required) +- `chat_id`: chat id from PPTOutlineGenerate API return(required) +- `outline`: ppt outline from PPTOutlineGenerate API return,must be in markdown format.Users can make appropriate modifications to the content, adding, modifying or deleting parts of the outline.(required) +- `query`: user orgin query(required) +- `title`: ppt title from PPTOutlineGenerate API return(required) +- `style_id`: ppt stype id from PPTThemeQuery API return(required) +- `tpl_id`: ppt template id from PPTThemeQuery API return(required) +- `resource_url`: the url of the resource file, such as pdf, word, txt, etc. +- `custom_tpl_url`: The path of the user-defined PPT template must be downloadable +- `gen_mode`: the generation mode of the ppt, optional values: 1,2 (1: Intelligent touch-ups, 2: Creative Mode) +- `ai_info`: Information on whether to use AI-generated PPT on the last page of the generated PPT + + +#### Example Usage +```bash +BAIDU_API_KEY=xxx python3 scripts/ppt_generate.py --query_id "xxx" --chat_id "xxx" ... +``` \ No newline at end of file diff --git a/_meta.json b/_meta.json new file mode 100644 index 0000000..5ef5186 --- /dev/null +++ b/_meta.json @@ -0,0 +1,6 @@ +{ + "ownerId": "kn77kbjpenv5qx583b5cas9tx980fmxt", + "slug": "ai-ppt-generate", + "version": "1.0.0", + "publishedAt": 1770217225629 +} \ No newline at end of file diff --git a/scripts/ppt_generate.py b/scripts/ppt_generate.py new file mode 100644 index 0000000..a2936e0 --- /dev/null +++ b/scripts/ppt_generate.py @@ -0,0 +1,73 @@ +import os +import sys +import requests +import json +import argparse + + +def ppt_generate(api_key: str, query_id: int, chat_id: int, query: str, outline: str, title: str, style_id: int, + tpl_id: int, resource_url: str, custom_tpl_url: str, gen_mode: int, ai_info: bool = False): + url = "https://qianfan.baidubce.com/v2/tools/ai_ppt/generate_ppt_by_outline" + headers = { + "Authorization": "Bearer %s" % api_key, + "Content-Type": "application/json" + } + headers.setdefault('Accept', 'text/event-stream') + headers.setdefault('Cache-Control', 'no-cache') + headers.setdefault('Connection', 'keep-alive') + params = { + "query_id": query_id, + "chat_id": chat_id, + "query": query, + "outline": outline, + "title": title, + "style_id": style_id, + "tpl_id": tpl_id, + "ai_info": ai_info + } + if resource_url: + params["resource_url"] = resource_url + if custom_tpl_url: + params["custom_tpl_url"] = custom_tpl_url + if gen_mode: + params["gen_mode"] = gen_mode + with requests.post(url, headers=headers, json=params, stream=True) as response: + response.raise_for_status() + for line in response.iter_lines(): + line = line.decode('utf-8') + if line and line.startswith("data:"): + data_str = line[5:].strip() + yield json.loads(data_str) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="ppt outline generate input parameters") + parser.add_argument("--query_id", "-qi", type=int, required=True, help="query id") + parser.add_argument("--chat_id", "-ci", type=int, required=True, help="chat id") + parser.add_argument("--outline", "-o", type=str, required=True, help="ppt outline,markdown format") + parser.add_argument("--query", "-q", type=str, required=True, help="user origin query") + parser.add_argument("--title", "-t", type=str, required=True, help="ppt title") + parser.add_argument("--style_id", "-si", type=int, required=True, help="style id") + parser.add_argument("--tpl_id", "-ti", type=int, required=True, help="template id") + parser.add_argument("--resource_url", "-ru", type=str, default=None, + help="Resource file URL, supporting formats such as documents and images (supported formats: doc, pdf, ppt, pptx, png, jpeg, jpg)") + parser.add_argument("--custom_tpl_url", "-ctu", type=str, default=None, + help="user custom ppt template url, must can be download") + parser.add_argument("--gen_mode", "-gm", type=int, default=None, choices=[1, 2], + help="PPT generation mode: 1: Intelligent polishing; 2: Strict compliance") + parser.add_argument("--ai_info", "-ai", type=bool, default=False, + help="If true, there will be information about the AI-generated PPT on the last page of the generated PPT") + args = parser.parse_args() + + api_key = os.getenv("BAIDU_API_KEY") + if not api_key: + print("Error: BAIDU_API_KEY must be set in environment.") + sys.exit(1) + try: + results = ppt_generate(api_key, args.query_id, args.chat_id, args.query, args.outline, args.title, args.style_id, + args.tpl_id, args.resource_url, args.custom_tpl_url, args.gen_mode, args.ai_info) + for result in results: + print(json.dumps(result, ensure_ascii=False, indent=2)) + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1) diff --git a/scripts/ppt_outline_generate.py b/scripts/ppt_outline_generate.py new file mode 100644 index 0000000..cb50fd9 --- /dev/null +++ b/scripts/ppt_outline_generate.py @@ -0,0 +1,67 @@ +import os +import sys +import requests +import json +import argparse + + +def ppt_outline_generate(api_key: str, query: str, resource_url: str = None, page_range: str = None, + layout: int = None, language_option: str = "default", gen_mode: int = None): + url = "https://qianfan.baidubce.com/v2/tools/ai_ppt/generate_outline" + headers = { + "Authorization": "Bearer %s" % api_key, + "Content-Type": "application/json" + } + headers.setdefault('Accept', 'text/event-stream') + headers.setdefault('Cache-Control', 'no-cache') + headers.setdefault('Connection', 'keep-alive') + params = { + "query": query, + } + if resource_url: + params["resource_url"] = resource_url + if page_range: + params["page_range"] = page_range + if layout: + params["layout"] = layout + if language_option: + params["language_option"] = language_option + if gen_mode: + params["gen_mode"] = gen_mode + with requests.post(url, headers=headers, json=params, stream=True) as response: + response.raise_for_status() + for line in response.iter_lines(): + line = line.decode('utf-8') + if line and line.startswith("data:"): + data_str = line[5:].strip() + yield json.loads(data_str) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="ppt outline generate input parameters") + parser.add_argument("--query", "-q", type=str, required=True, help="query, ppt title or topic") + parser.add_argument("--resource_url", "-ru", type=str, default=None, + help="Resource file URL, supporting formats such as documents and images (supported formats: doc, pdf, ppt, pptx, png, jpeg, jpg)") + parser.add_argument("--page_range", "-pr", type=str, default=None, + choices=['1-10', '11-20', '21-30', '31-40', '40+'], + help="ppt page number of range,enums:['1-10','11-20','21-30','31-40','40+']") + parser.add_argument("--layout", "-l", type=int, default=None, choices=[1, 2], + help="Layout modes: 1: Minimalist Mode, 2: Professional Mode") + parser.add_argument("--language_option", "-lg", type=str, default="default", choices=["default", "en", "zh"], + help="language option,support en,zh") + parser.add_argument("--gen_mode", "-gm", type=int, default=None, choices=[1, 2], + help="PPT generation mode: 1: Intelligent polishing; 2: Strict compliance") + args = parser.parse_args() + + api_key = os.getenv("BAIDU_API_KEY") + if not api_key: + print("Error: BAIDU_API_KEY must be set in environment.") + sys.exit(1) + try: + results = ppt_outline_generate(api_key, args.query, args.resource_url, args.page_range, args.layout, + args.language_option, args.gen_mode) + for result in results: + print(json.dumps(result, ensure_ascii=False, indent=2)) + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1) diff --git a/scripts/ppt_theme_list.py b/scripts/ppt_theme_list.py new file mode 100644 index 0000000..6998b7e --- /dev/null +++ b/scripts/ppt_theme_list.py @@ -0,0 +1,30 @@ +import os +import sys +import requests +import json + + +def ppt_theme_list(api_key: str): + url = "https://qianfan.baidubce.com/v2/tools/ai_ppt/get_ppt_theme" + headers = { + "Authorization": "Bearer %s" % api_key, + } + response = requests.post(url, headers=headers) + response.raise_for_status() + result = response.json() + if "errno" in result and result["errno"] != 0: + raise RuntimeError(result["errmsg"]) + return result["data"]["ppt_themes"] + + +if __name__ == "__main__": + api_key = os.getenv("BAIDU_API_KEY") + if not api_key: + print("Error: BAIDU_API_KEY must be set in environment.") + sys.exit(1) + try: + results = ppt_theme_list(api_key) + print(json.dumps(results, indent=2)) + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1) \ No newline at end of file