跳转到主内容
全部文档

写自己的编排

内置编排正好缺你要的那一条时,自己写一条。编排是一份纯文本 YAML,存进 ~/.42md/recipes/,就能和内置的一样按名字运行。

一份最小的编排

下面这条把外文 PDF 转成中文,再导出 EPUB。存成 ~/.42md/recipes/pdf2zhbook.yaml:

yaml
name: pdf2zhbookdescription: 外文 PDF → 中文 → EPUB 电子书steps:  - id: extract    run: acquire    with: ["{{ input }}"]    produces: md  - id: translate    run: tools.translate    with: ["{{ steps.extract.output }}", "--target", "中文"]    billed: true  - id: book    run: tools.md2epub    with: ["{{ steps.translate.output }}"]output: "{{ steps.book.output }}"

存好就能跑:

bash
42md recipe list42md recipe run pdf2zhbook 论文.pdf

~/.42md/recipes/ 里的编排和内置同名时,用你自己的那份。想改内置编排,复制一份同名的改就行。

各字段的意思

字段做什么
name名字,按它运行。中文、英文都行,最多 40 字;不能有 / \ : * ? " < > | 这几个符号。名字里有空格时,命令行里加引号:42md recipe run "会议 纪要" …
description一句话说明,recipe list 里显示
params可选,声明运行时可以改的参数
steps步骤,从上往下依次跑
steps[].id这一步的代号,后面用它引用产物
steps[].run这一步调哪个动作
steps[].with传给动作的参数,就是你平时在命令行写的那些
steps[].produces可选,一步产出多个文件时,指定往下传哪种扩展名
steps[].billed这一步花点数时标上 true,开跑前会提示
output最后交给你哪一步的产物,不写就取最后一步
deliver可选,写 all 时每一步的产物都留下

with 里有三种占位写法:

  • {{ input }}:运行时给的文件、目录或网址
  • {{ params.<名> }}:你声明的参数
  • {{ steps.<id>.output }}:前面某一步的产物

能调哪些动作

run 的值以这条命令列出的为准,它跟着你装的版本走:

bash
42md recipe verbs
动作做什么计费
acquire转成 Markdown(文档、网页、录音)多数免费;扫描件识别、录音转写计费
tools.lint / tools.t2s版式优化 / 繁体转简体免费
tools.translate / tools.improve / tools.summarize / tools.hotwords翻译 / 优化 / 摘要 / 热词花点数
tools.md2pdf / tools.md2docx / tools.md2epub / tools.md2html / tools.md2wechat导出 PDF / Word / EPUB / HTML / 公众号免费
tools.merge / tools.split合并 / 拆分免费
tools.download / tools.screenshot批量下载 PDF / 网页截图免费
tools.scan / tools.inspect / tools.compress扫描 / 体检 / 瘦身源文件免费
tools.redact本地脱敏免费

每个 tools.<名> 能接哪些参数,看 42md tools <名> --help。

参数:一条编排换着用

把会变的地方声明成参数,运行时用 --set 改:

yaml
name: pdf2anyparams:  - name: lang    description: 目标语言    default: 中文steps:  - id: extract    run: acquire    with: ["{{ input }}"]    produces: md  - id: translate    run: tools.translate    with: ["{{ steps.extract.output }}", "--target", "{{ params.lang }}"]    billed: trueoutput: "{{ steps.translate.output }}"
bash
42md recipe run pdf2any 论文.pdf --set lang=日语

参数必须填时,把 default 换成 required: true。

跑之前先校验

写错一个动作名,前面花了点数的步骤会白跑。开跑前查一遍:

bash
42md recipe validate ~/.42md/recipes/pdf2zhbook.yaml42md recipe run pdf2zhbook 论文.pdf --dry-run

validate 检查动作是否存在、参数有没有声明、引用的步骤对不对;--dry-run 把整条计划列出来,不执行、不扣费。

手头的 YAML 不想先存进目录,也可以直接跑:

bash
42md recipe run -f 我的编排.yaml 论文.pdf

在网页上用一句话生成

网页版「工具箱 → 我的编排 → 新建编排」,在「AI 帮你生成编排」里用一句话说你要做什么,点生成,AI 把 YAML 写好填进表单,你看过、改好再保存。也可以从「内置模板」挑一条照着改。

  • 生成这一步花点数,点之前会弹窗显示预估消耗,可以取消。
  • 保存不收费,最多存 10 条。
  • 存好的编排在命令行按名字运行:42md recipe run <名称> <输入>。和本机 ~/.42md/recipes/ 或内置同名时,优先用本机和内置的那份,给网页上的改个名就行。
/2