8
n8n 中文网amn8n.com

生成长文档

中级

这是一个Content Creation, Multimodal AI领域的自动化工作流,包含 14 个节点。主要使用 Set, Form, SplitOut, GoogleDocs, FormTrigger 等节点。 使用GPT-5和Google Docs从简单标题生成长篇文档

前置要求
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "TkSOqdrMsNs3WpDK",
  "meta": {
    "instanceId": "a0e41110bf9f611e96e18e0663d80d746aeedc58368940bfe471a8d577a5069b",
    "templateCredsSetupCompleted": true
  },
  "name": "生成长文档",
  "tags": [],
  "nodes": [
    {
      "id": "60f4490d-4cb9-4cc6-bf22-cd106c3ffef2",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        496,
        48
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"blogTitle\": \"How to Build an AI Automation Workflow with n8n\",\n  \"sections\": [\n    {\n      \"sectionId\": 1,\n      \"sectionTitle\": \"Introduction: Why AI Automation Matters\",\n      \"sectionSummary\": \"Explain the rise of AI automation and why it's valuable for productivity.\"\n    },\n    {\n      \"sectionId\": 2,\n      \"sectionTitle\": \"Tools You Need to Get Started\",\n      \"sectionSummary\": \"List and briefly describe essential tools like n8n, OpenAI API, and Supabase.\"\n    },\n    {\n      \"sectionId\": 3,\n      \"sectionTitle\": \"Step-by-Step Workflow Setup\",\n      \"sectionSummary\": \"Break down how to connect nodes, triggers, and APIs to build the automation.\"\n    },\n    {\n      \"sectionId\": 4,\n      \"sectionTitle\": \"Testing and Optimization\",\n      \"sectionSummary\": \"Show how to test, debug, and improve the automation workflow.\"\n    },\n    {\n      \"sectionId\": 5,\n      \"sectionTitle\": \"Conclusion and Next Steps\",\n      \"sectionSummary\": \"Wrap up the article and encourage readers to experiment with AI workflows.\"\n    }\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "0aa103cc-e536-4041-a546-bf2ad16cd58d",
      "name": "分离输出",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        928,
        -192
      ],
      "parameters": {
        "include": "allOtherFields",
        "options": {},
        "fieldToSplitOut": "sections"
      },
      "typeVersion": 1
    },
    {
      "id": "84a0b969-dcf6-484a-ac18-5ca1663926d0",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1152,
        -192
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "ad643365-42ef-4e62-9c3d-7da17915bb09",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1520,
        -80
      ],
      "parameters": {
        "sessionKey": "={{ $('GetSections').item.json.documentId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 30
      },
      "typeVersion": 1.3
    },
    {
      "id": "69495066-646b-4cd5-8bb2-01abb95c67c7",
      "name": "获取章节",
      "type": "n8n-nodes-base.set",
      "position": [
        704,
        -192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5b79fc5b-55ae-42ed-a138-9150a7b86c70",
              "name": "sections",
              "type": "array",
              "value": "={{ $json.output.sections }}"
            },
            {
              "id": "73ed193b-9d56-4229-a1da-89037a241a3e",
              "name": "documentId",
              "type": "string",
              "value": "={{ Math.random().toString(36).substring(2, 10).toUpperCase() }}"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "d45e18a1-274b-42f8-a516-cdd7fa472703",
      "name": "创建文档",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        128,
        -336
      ],
      "parameters": {
        "title": "={{ $('On form submission').item.json.Title }}",
        "folderId": "default"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "ue3sXJAM99TJeGwG",
          "name": "Google Docs account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "3da122af-c430-4dc0-a237-2fd6008f5e0c",
      "name": "更新文档",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        1728,
        -192
      ],
      "parameters": {
        "actionsUi": {
          "actionFields": [
            {
              "text": "={{$json.output + \"\\n\\n\"}}\n",
              "action": "insert"
            }
          ]
        },
        "operation": "update",
        "documentURL": "={{ $('CreateDocument').item.json.id }}"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "ue3sXJAM99TJeGwG",
          "name": "Google Docs account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "988ad51b-7a09-4712-907e-d852a4d228ef",
      "name": "gpt-5-mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        368,
        48
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini",
          "cachedResultName": "gpt-5-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "2TBvwobWbbHlIjKT",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "033dd289-00c8-4753-b0b1-0f78cdfd9e63",
      "name": "gpt-5",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1392,
        -80
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5",
          "cachedResultName": "gpt-5"
        },
        "options": {
          "timeout": 600000
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "2TBvwobWbbHlIjKT",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "17a2ab80-75e7-4f72-92cb-c4d06b2fbf3c",
      "name": "内容撰写器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1376,
        -304
      ],
      "parameters": {
        "text": "=Help write section:  {{ $json.sections.sectionId }}. {{ $json.sections.sectionTitle }}",
        "options": {
          "systemMessage": "=You are a professional content generator and technical writer.  \nYour task is to generate complete Markdown sections based on a provided JSON structure.\n\n#JSON structure:\n{{ $('ContentPlanner').item.json.output.toJsonString() }}\n\n# 🧠 Instructions\nGenerate a complete, well-structured Markdown document.\nInclude all sections in order using their **sectionId**.\nEach section should include:\n- Heading in the format: `# {sectionId}. {sectionTitle}`  \n- Section must not exceed {{Math.floor($('On form submission').item.json['Word Count'] / $('GetSections').item.json.sections.length)}} words\n\n",
          "passthroughBinaryImages": false
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "338f10a7-01f3-454e-bd82-4b59b2be54f3",
      "name": "内容规划器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        352,
        -192
      ],
      "parameters": {
        "text": "={{ $('On form submission').item.json.Title }}",
        "options": {
          "systemMessage": "# ✍️ Prompt: Blog Outline Generator Agent\n\n## **Role**\nYou are a **professional content planner and blog strategist**.\n\n## **Goal**\nAnalyze the user’s topic or idea, then **generate a complete blog post outline** with clear structure, logical flow, and engaging section titles.\n\n## **Instructions**\n1. Read the user’s description or topic carefully.  \n2. Identify the **main goal** of the article (inform, persuade, educate, or inspire).  \n3. Create a **structured outline** with key sections and short explanations for each.  \n4. Include **subheadings** (H2, H3) and **logical progression** from introduction to conclusion.  \n5. Focus on **clarity, SEO-friendly phrasing, and reader engagement**.  \n6. Do **not** write the full article — only the **outline and section summaries**."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "67ecec8d-12d3-4923-bbde-ca710d2465d4",
      "name": "表单提交时",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -96,
        -336
      ],
      "webhookId": "9525bb2f-3046-43ee-872a-9f5ee8c32248",
      "parameters": {
        "options": {},
        "formTitle": "Generate Long Content",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Title",
              "placeholder": "title or short description",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Word Count",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Help generate long document from a title"
      },
      "typeVersion": 2.3
    },
    {
      "id": "6e4ebbe6-c39d-4b9a-832a-69824b207f06",
      "name": "表单",
      "type": "n8n-nodes-base.form",
      "position": [
        416,
        -480
      ],
      "webhookId": "bc18f06b-e004-4e39-b7f0-eed867ec524a",
      "parameters": {
        "options": {
          "customCss": ":root {\n\t--font-family: 'Open Sans', sans-serif;\n\t--font-weight-normal: 400;\n\t--font-weight-bold: 600;\n\n\t/* Typography — larger & more readable */\n\t--font-size-body: 16px;\n\t--font-size-label: 15px;\n\t--font-size-test-notice: 13px;\n\t--font-size-input: 15px;\n\t--font-size-header: 24px;\n\t--font-size-paragraph: 16px;\n\t--font-size-link: 14px;\n\t--font-size-error: 13px;\n\t--font-size-html-h1: 34px;\n\t--font-size-html-h2: 26px;\n\t--font-size-html-h3: 20px;\n\t--font-size-html-h4: 18px;\n\t--font-size-html-h5: 16px;\n\t--font-size-html-h6: 14px;\n\t--font-size-subheader: 16px;\n\n\t/* Colors — higher contrast & friendlier accents */\n\t--color-background: #f7f8fc;\n\t--color-test-notice-text: #b45309;     /* deeper amber for contrast */\n\t--color-test-notice-bg: #fff7ed;\n\t--color-test-notice-border: #fed7aa;\n\n\t--color-card-bg: #ffffff;\n\t--color-card-border: #e5e7eb;\n\t--color-card-shadow: rgba(31, 41, 55, 0.06);\n\n\t--color-link: #2563eb;                 /* accessible blue for standard links */\n\t--color-header: #1f2937;               /* slate-800 */\n\t--color-label: #374151;                /* slate-700 */\n\t--color-input-border: #cbd5e1;         /* slate-300 */\n\t--color-input-text: #111827;           /* slate-900 */\n\t--color-focus-border: #7c3aed;         /* vivid violet focus ring */\n\t--color-submit-btn-bg: #ff6d5a;        /* brand coral kept */\n\t--color-submit-btn-text: #ffffff;\n\t--color-error: #dc2626;                /* red-600 */\n\t--color-required: #ef4444;             /* red-500 */\n\t--color-clear-button-bg: #6b7280;      /* slate-500 */\n\t--color-html-text: #374151;            /* slate-700 */\n\t--color-html-link: #ff6d5a;            /* brand accent for content links */\n\t--color-header-subtext: #6b7280;       /* slate-500 */\n\n\t/* Border Radii — slightly softer */\n\t--border-radius-card: 10px;\n\t--border-radius-input: 8px;\n\t--border-radius-clear-btn: 50%;\n\t--card-border-radius: 10px;\n\n\t/* Spacing — room to breathe */\n\t--padding-container-top: 32px;\n\t--padding-card: 28px;\n\t--padding-test-notice-vertical: 12px;\n\t--padding-test-notice-horizontal: 24px;\n\t--margin-bottom-card: 20px;\n\t--padding-form-input: 14px;\n\t--card-padding: 28px;\n\t--card-margin-bottom: 20px;\n\n\t/* Dimensions — wider layout */\n\t--container-width: 720px;\n\t--submit-btn-height: 52px;\n\t--checkbox-size: 20px;\n\n\t/* Others — subtle shadow & clearer placeholders */\n\t--box-shadow-card: 0px 6px 20px 0px var(--color-card-shadow);\n\t--opacity-placeholder: 0.6;\n}\n"
        },
        "operation": "completion",
        "completionTitle": "Generating your document… Please wait a few minutes, then access the link below",
        "completionMessage": "=https://docs.google.com/document/d/{{ $('CreateDocument').item.json.id }}"
      },
      "typeVersion": 2.3
    },
    {
      "id": "f3db576d-70cb-46ce-a6ec-f291c486807e",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        -592
      ],
      "parameters": {
        "width": 848,
        "height": 992,
        "content": "# 🧭 概述"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "aac61755-8db8-4852-b401-a5cb8e5c21ef",
  "connections": {
    "gpt-5": {
      "ai_languageModel": [
        [
          {
            "node": "ContentWriter",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gpt-5-mini": {
      "ai_languageModel": [
        [
          {
            "node": "ContentPlanner",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GetSections": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ContentWriter": {
      "main": [
        [
          {
            "node": "UpdateDocument",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "ContentWriter",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "ContentPlanner": {
      "main": [
        [
          {
            "node": "GetSections",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CreateDocument": {
      "main": [
        [
          {
            "node": "Form",
            "type": "main",
            "index": 0
          },
          {
            "node": "ContentPlanner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "UpdateDocument": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "ContentWriter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "CreateDocument",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "ContentPlanner",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 内容创作, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量14
分类2
节点类型11
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Nghia Nguyen

Nghia Nguyen

@nghiaaidev

I am Nguyen Trung Nghia, a Software Engineer passionate about AI Automation. I build intelligent automation systems that help businesses reduce costs, increase productivity, and scale faster with the power of AI technology.

外部链接
在 n8n.io 查看

分享此工作流