8
n8n 中文网amn8n.com

支持Webhook的AI PDF分析器

高级

这是一个自动化工作流,包含 16 个节点。主要使用 If, Set, Code, Crypto, Webhook 等节点。 支持Webhook的AI PDF分析器

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • OpenAI API Key

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "ff412ab2a6cd55af5dedbbab9b8e43f0f3a0cb16fb794fa8d3837f957b771ad2",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "505f25b4-eaa7-4d42-98d9-2154d7d4cc81",
      "name": "文件引用",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -1360,
        280
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "59721669-a3a9-48ab-8cb0-29ea0af84f6d",
      "name": "成功 1",
      "type": "n8n-nodes-base.respondToWebhook",
      "onError": "continueRegularOutput",
      "position": [
        620,
        -20
      ],
      "parameters": {
        "options": {
          "responseCode": 200,
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        },
        "respondWith": "json",
        "responseBody": "={{\n{\n  \"error\": null,\n  \"meta\": {\n    \"hash\": $('Get File Hash').first().json.data,\n  },\n  \"result\": $json.response\n}\n}}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "16479572-c3a6-4127-9bf2-db7380bd734c",
      "name": "是有效文件吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        -660,
        280
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a277fc5c-6873-49d5-b67b-39df0efc8a61",
              "operator": {
                "type": "number",
                "operation": "lte"
              },
              "leftValue": "={{ $('Get Filesize').item.json.filesize_in_bytes }}",
              "rightValue": "={{ 10000000 }}"
            },
            {
              "id": "d908d5a9-3550-45ce-8645-19c08d3e5982",
              "operator": {
                "type": "number",
                "operation": "lte"
              },
              "leftValue": "={{ $json.numpages }}",
              "rightValue": 20
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d35868fb-2a0b-4f07-a942-216a8d226b46",
      "name": "获取文件大小",
      "type": "n8n-nodes-base.code",
      "position": [
        -980,
        280
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "function convertToBytes(size) {\n    const units = {\n        b: 1,\n        bytes: 1,\n        kb: 1024,\n        mb: 1024 * 1024,\n        gb: 1024 * 1024 * 1024,\n    };\n\n    // Extract the number and unit using regex\n    const regex = /([\\d.]+)\\s*(bytes|b|kb|mb|gb)/i;\n    const match = size.match(regex);\n\n    if (!match) {\n        throw new Error(`Invalid size format: \"${size}\"`);\n    }\n\n    const value = parseFloat(match[1]);\n    const unit = match[2].toLowerCase();\n\n    // Calculate the size in bytes\n    const factor = units[unit];\n    if (!factor) {\n        throw new Error(`Unsupported unit: \"${unit}\"`);\n    }\n\n    return Math.round(value * factor);\n}\n\nconst data = $('File Ref').first().binary.data;\n\nreturn {\n  json: { filesize_in_bytes: convertToBytes(data.fileSize) },\n  binary: { data }\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "87e6b82c-4099-4435-b47f-647ae0b97d39",
      "name": "从文件提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -820,
        280
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "e4f623cd-418b-49f1-bc1b-2e804a089617",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1040,
        140
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 480,
        "content": "### 2. 验证 PDF 文件"
      },
      "typeVersion": 1
    },
    {
      "id": "ece12347-4205-447a-85cd-298bfa7595e0",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -280,
        -120
      ],
      "parameters": {
        "color": 7,
        "width": 600,
        "height": 480,
        "content": "### 3. 使用 Gemini API 进行文档解析"
      },
      "typeVersion": 1
    },
    {
      "id": "c7197f2f-7ac9-4c97-bd58-859c1d0950f0",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        -120
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 280,
        "content": "### 5. 格式化响应"
      },
      "typeVersion": 1
    },
    {
      "id": "9ef4b032-de21-48bd-ad3a-fb1cf391fe77",
      "name": "信息提取器",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "onError": "continueErrorOutput",
      "position": [
        -180,
        40
      ],
      "parameters": {
        "text": "=Document as follows:\n{{ $json.text }}",
        "options": {
          "systemPromptTemplate": "You are a note-taking agent helping the user to summarise this PDF in note form. Breakdown the document into distinct topics and provide a 3 paragraph summary of each topic discussed in the document."
        },
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n     \"properties\": {\n       \"topic\": { \"type\": \"string\" },\n       \"insights\": {\n         \"type\": \"array\",\n         \"items\": {\n           \"type\": \"object\",\n           \"properties\": {\n             \"title\": { \"type\": \"string\" },\n             \"body\": { \"type\": \"string\" }\n           }\n         }\n       }\n     }\n  }\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "4d9f3117-972b-417b-9dee-4098bbd71102",
      "name": "格式化响应",
      "type": "n8n-nodes-base.set",
      "position": [
        440,
        -20
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "10335d9e-7e0a-4ee1-a275-71d2f75b6bba",
              "name": "response",
              "type": "string",
              "value": "={{\n$json.output.map(item => {\nreturn\n`## ${item.topic}\n${item.insights.map(insight =>\n`- **${insight.title}**: ${insight.body}`\n).join('\\n')}\n`;\n}).join('\\n\\n');\n}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "db32ecb9-79d0-45ee-aced-05aca99c9f27",
      "name": "400 错误",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -480,
        440
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "json",
        "responseBody": "{\n  \"error\": \"Unable to parse document. Please ensure file is less than 10mb with maximum of 20 pages.\",\n  \"result\": []\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "61d6e5e7-dcd7-4cdc-82be-8fec58f26e5a",
      "name": "500 错误",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        140,
        120
      ],
      "parameters": {
        "options": {
          "responseCode": 500
        },
        "respondWith": "json",
        "responseBody": "{\n  \"error\": \"Unable to parse document. An unknown error occurred.\",\n  \"result\": []\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "732d7d7b-f7f5-4342-93b7-e8b49d381dfb",
      "name": "获取文件哈希",
      "type": "n8n-nodes-base.crypto",
      "disabled": true,
      "position": [
        -1180,
        280
      ],
      "parameters": {
        "value": "={{ $('File Ref').first().binary }}"
      },
      "typeVersion": 1
    },
    {
      "id": "e6221a49-d4d8-4aa5-bbd8-69b885ff7254",
      "name": "POST /ai_pdf_summariser",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1520,
        280
      ],
      "webhookId": "a452fbcb-c7c4-4c0b-b435-b1829d411e7a",
      "parameters": {
        "path": "ai_pdf_summariser",
        "options": {
          "ignoreBots": false
        },
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "3d605049-571f-45d2-b1ba-914f0c9d68f4",
      "name": "便签9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1680,
        140
      ],
      "parameters": {
        "width": 280,
        "height": 100,
        "content": "### POST /ai_pdf_summariser"
      },
      "typeVersion": 1
    },
    {
      "id": "d79d5cf3-2f7c-459c-9977-9e0a77ed8d7b",
      "name": "OpenAI 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -100,
        220
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "pY9tCO8MgTcBYqdJ",
          "name": "OpenAi account Tutorial from docs"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "pinData": {},
  "connections": {
    "File Ref": {
      "main": [
        [
          {
            "node": "Get File Hash",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Filesize": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get File Hash": {
      "main": [
        [
          {
            "node": "Get Filesize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Valid File?": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "400 Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response": {
      "main": [
        [
          {
            "node": "Success1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Is Valid File?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "500 Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POST /ai_pdf_summariser": {
      "main": [
        [
          {
            "node": "File Ref",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级

需要付费吗?

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

工作流信息
难度等级
高级
节点数量16
分类-
节点类型11
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
n8n Team

n8n Team

@n8n-team

Meet the official n8n team. We specialize in building workflows that transform intricate tasks into seamless operations.

外部链接
在 n8n.io 查看

分享此工作流