8
n8n 中文网amn8n.com

使用Google Forms和Gemini AI将YouTube视频转换为交互式选择题测验

高级

这是一个Document Extraction, Multimodal AI领域的自动化工作流,包含 20 个节点。主要使用 If, Set, Code, Form, FormTrigger 等节点。 使用Google Forms和Gemini AI将YouTube视频转换为交互式选择题测验

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "d80b5150263fe72aa8e869b415c9976cc4068f6d829d47aec881a843e81db62f",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "a9d881c8-7bd2-4731-9190-dfdc71feee7c",
      "name": "设置字段:定义结果",
      "type": "n8n-nodes-base.set",
      "position": [
        -1380,
        670
      ],
      "parameters": {
        "include": "except",
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "300bfbe7-8d13-41ba-8828-17bba1d0eabe",
              "name": "answerAIGenerated",
              "type": "string",
              "value": "={{ $json.candidates[0].content.parts[0].text }}"
            },
            {
              "id": "a54eeb5d-e4de-4fd9-a15c-be51cc414c46",
              "name": "promptTokenCount",
              "type": "string",
              "value": "={{ $json.usageMetadata?.promptTokenCount ? $json.usageMetadata.promptTokenCount : ($json.error ? $json.error : \"No content or error found\") }}"
            },
            {
              "id": "dd590788-069e-48d9-adb2-6a5d10f8af2f",
              "name": "candidatesTokenCount",
              "type": "string",
              "value": "={{ $json.usageMetadata?.candidatesTokenCount ? $json.usageMetadata.candidatesTokenCount : ($json.error ? $json.error : \"No content or error found\") }}"
            },
            {
              "id": "23766495-25df-4d3d-bc62-9e79a860ee19",
              "name": "totalTokenCount",
              "type": "string",
              "value": "={{ $json.usageMetadata?.totalTokenCount ? $json.usageMetadata.totalTokenCount : ($json.error ? $json.error : \"No content or error found\") }}"
            },
            {
              "id": "cfad5ba2-a2c5-48ff-b64b-9131a51fd23c",
              "name": "modelVersionUsed",
              "type": "string",
              "value": "={{ $json.modelVersion ? $json.modelVersion : ($json.error ? $json.error : \"No content or error found\") }}"
            }
          ]
        },
        "excludeFields": "candidates, usageMetadata",
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "0ad13e7e-0184-4a95-b58f-5949849eba0c",
      "name": "条件判断:是否检测到错误?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1600,
        795
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "148e9a72-f826-468c-86a3-471873717ed4",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.candidates[0].content.parts[0].text }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "14b9683c-e1f4-4559-865b-a345da7d7146",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1160,
        900
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "IjyqMmAoW1g4h2Uq",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1b283330-f4e9-44b6-aebf-018d45c7f9e4",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -960,
        900
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"Questions\": [{\"question\": \"In unsupervised learning, are we given data associated with output labels?\",    \"options\": [\"Yes\",\"No\",\"Sometimes\",\"Depends on the situation\"], \"answer\": \"No\"},\n{\"question\": \"In unsupervised learning, are we given data associated with output labels?\",    \"options\": [\"Yes\",\"No\",\"Sometimes\",\"Depends on the situation\"], \"answer\": \"No\"}]\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "8040c890-8a38-455a-a5b9-064bfb5d24b1",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        0,
        420
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "0a9c007e-7767-4849-bd05-d0b1ecb5c14c",
      "name": "筛选器",
      "type": "n8n-nodes-base.if",
      "position": [
        -2260,
        945
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "148e9a72-f826-468c-86a3-471873717ed4",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json['Number of Questions'] }}",
              "rightValue": 91
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e963159e-716a-4693-b03e-b7646a1322ac",
      "name": "输入 YouTube URL",
      "type": "n8n-nodes-base.formTrigger",
      "notes": "https://youtu.be/cZQPDLgPtNg?si=Ze6zOu5oTpF8QMq0",
      "position": [
        -2480,
        945
      ],
      "webhookId": "e2885d2e-0bd8-4891-916c-0c679782869d",
      "parameters": {
        "options": {
          "buttonLabel": "Generate Quizes"
        },
        "formTitle": "Quize Form YT Videos",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Form Name",
              "requiredField": true
            },
            {
              "fieldType": "email",
              "fieldLabel": "Email"
            },
            {
              "fieldLabel": "Youtube URL",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Number of Questions",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Wait a few minutes after submitting the form to generate quiz.\nLIMITATIONS: Number of questions up to 90, Video size up to 50 minutes."
      },
      "typeVersion": 2.2
    },
    {
      "id": "8d7b2422-a214-4993-af3f-f898e3ca190f",
      "name": "设置提示和模型",
      "type": "n8n-nodes-base.set",
      "position": [
        -2040,
        870
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8be68e95-53df-492f-a88a-14c06f51f531",
              "name": "=prompt",
              "type": "string",
              "value": "=Generate {{ $json['Number of Questions'] }} MCQ (Multiple Choice Question) from the video with answer, every question will have 3 options and return those question as json format."
            },
            {
              "id": "b445c2da-934f-4a78-a57b-f383d8950f8a",
              "name": "model",
              "type": "string",
              "value": "gemini-2.5-flash"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "b6c30d65-0157-4856-a5c7-05dc73db566e",
      "name": "HTTP 请求到 Gemini",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        -1820,
        870
      ],
      "parameters": {
        "url": "=https://generativelanguage.googleapis.com/v1beta/models/{{ $json.model }}:generateContent?key=API_KEY",
        "method": "POST",
        "options": {
          "timeout": 100000000
        },
        "jsonBody": "={\n  \"contents\": [{\n    \"parts\": [\n      { \"text\": {{ JSON.stringify($json.prompt) }} },\n      { \"file_data\": { \"file_uri\": \"{{ $json['Youtube URL'] }}\" } }\n    ]\n  }]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": false
    },
    {
      "id": "20189418-6cfe-4bf3-b4ac-dad375673dab",
      "name": "提取 JSON",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "onError": "continueErrorOutput",
      "position": [
        -1160,
        670
      ],
      "parameters": {
        "text": "=extract the json from this text:  {{ $json.answerAIGenerated }}",
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.5
    },
    {
      "id": "93b3900b-02b2-44e0-b167-7e337b7e2135",
      "name": "创建 Google 表单",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        -660,
        520
      ],
      "parameters": {
        "url": "=https://forms.googleapis.com/v1/forms",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"info\": {\n    \"title\": \"{{ $node[\"Input YouTube URL\"].json['Form Name'] }}\",\n    \"documentTitle\": \"{{ $node[\"Input YouTube URL\"].json['Form Name'] }}-{{ $now }}\"\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "googleOAuth2Api"
      },
      "credentials": {
        "googleOAuth2Api": {
          "id": "Tw34H08H15Fzwz4G",
          "name": "Google forms account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "93e8ca01-8c33-40f2-b925-d9dc485b7940",
      "name": "为 API 调用准备问题",
      "type": "n8n-nodes-base.code",
      "position": [
        -260,
        420
      ],
      "parameters": {
        "jsCode": "// This is what your Code node would generate for ONE question\nconst questionRequests = [];\n\n// Assuming 'questions' is the array of questions\nfor (const item of $('Extract JSON').first().json.output.Questions) { // $input.first().json.output.Questions) {\n  const options = [];\n  // Assuming item.json.Option1, item.json.Option2, etc. from Google Sheet\n  if (item.options[0]) options.push({ value: item.options[0] });\n  if (item.options[1]) options.push({ value: item.options[1] });\n  if (item.options[2]) options.push({ value: item.options[2] });\n\n  const correctAnswers = [{ value: item.answer }]; // Assuming item.json.CorrectAnswer\n\n  questionRequests.push(\n    {\"data\":[\n      {\n      \"updateSettings\": {\n        \"settings\": {\n          \"quizSettings\": {\n            \"isQuiz\": true\n          }\n        },\n        \"updateMask\": \"quizSettings.isQuiz\"\n      }\n      },\n      {\"createItem\": {\n      \"item\": {\n        \"title\": item.question, // Question text from Google Sheet\n        \"questionItem\": {\n          \"question\": {\n            \"choiceQuestion\": {\n              \"options\": options,\n              \"shuffle\": true, // Optional: Randomize order of options\n              \"type\": \"RADIO\"\n            },\n            \"grading\": {\n               // Points for the question\n              \"correctAnswers\": {\n                \"answers\": correctAnswers \n              },\n              \"pointValue\": 1,\n              \"whenRight\": {\n                  \"text\": \"Great job! That's correct.\"\n                },\n              \"whenWrong\": {\n                  \"text\": `Not quite. The correct answer was '${item.answer}'.`\n                }\n              \n            }\n          }\n        }\n      },\n      \"location\": {\n        \"index\": questionRequests.length // Adds questions in order\n      }\n    }\n  }]});\n}\n\n\nreturn questionRequests;"
      },
      "typeVersion": 2
    },
    {
      "id": "95142722-9a47-4f48-bece-9a7813f61a95",
      "name": "创建多选题测验",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "maxTries": 5,
      "position": [
        200,
        520
      ],
      "parameters": {
        "url": "=https://forms.googleapis.com/v1/forms/{{ $('Create a Google Form').first().json.formId }}:batchUpdate",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"requests\": {{ JSON.stringify($json.data) }}\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "googleOAuth2Api"
      },
      "credentials": {
        "googleOAuth2Api": {
          "id": "Tw34H08H15Fzwz4G",
          "name": "Google forms account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2
    },
    {
      "id": "ea54a41d-0b2d-4a8d-aede-e6f2b108f02a",
      "name": "错误输出",
      "type": "n8n-nodes-base.form",
      "position": [
        160,
        960
      ],
      "webhookId": "07b8f426-4177-47ed-bba6-27f968c6758f",
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "Something went wrong!",
        "completionMessage": "Please check your Youtube URL OR the number of questions. "
      },
      "typeVersion": 1
    },
    {
      "id": "68f30765-f7f4-472f-b144-f2988b65a693",
      "name": "重定向到 Google 表单",
      "type": "n8n-nodes-base.form",
      "position": [
        200,
        320
      ],
      "webhookId": "5dc0fe0e-fd39-4751-94f5-744616313e37",
      "parameters": {
        "operation": "completion",
        "redirectUrl": "={{ $('Create a Google Form').item.json.responderUri }}",
        "respondWith": "redirect"
      },
      "typeVersion": 1
    },
    {
      "id": "e4f108b5-884e-483c-a3d2-662096a91e2e",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2560,
        720
      ],
      "parameters": {
        "color": 4,
        "width": 460,
        "height": 420,
        "content": "## 通过 n8n 表单触发器获取输入(YouTube URL、表单名称、问题数量)"
      },
      "typeVersion": 1
    },
    {
      "id": "eb20cf7c-630d-43a7-9e80-53613196e632",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2080,
        560
      ],
      "parameters": {
        "color": 5,
        "width": 840,
        "height": 580,
        "content": "## 向 \"Gemini-2.5-flash\" 发送 \"HTTP 请求\" 以创建多选题测验"
      },
      "typeVersion": 1
    },
    {
      "id": "34233649-1635-43b3-b264-b0a6aa67d845",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1220,
        300
      ],
      "parameters": {
        "color": 6,
        "width": 820,
        "height": 840,
        "content": "## 将 Gemini 输出(多选题及其答案)转换为 json 格式并创建 Google 表单"
      },
      "typeVersion": 1
    },
    {
      "id": "6f2fb7b1-a5ab-444e-9dd7-ec6116e0f53c",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        100
      ],
      "parameters": {
        "width": 840,
        "height": 640,
        "content": "## 准备 json 以匹配 Google 表单 API 的结构来创建测验,并重定向到 Google 表单"
      },
      "typeVersion": 1
    },
    {
      "id": "0a103f0b-cd29-4952-b7e6-32887a4e6eb4",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        760
      ],
      "parameters": {
        "color": 3,
        "width": 840,
        "height": 380,
        "content": "## 错误处理的默认输出"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "filter": {
      "main": [
        [
          {
            "node": "Set Prompt and Model",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract JSON": {
      "main": [
        [
          {
            "node": "Create a Google Form",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Redirect to Google Form",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create MCQ Quizzes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Input YouTube URL": {
      "main": [
        [
          {
            "node": "filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create MCQ Quizzes": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a Google Form": {
      "main": [
        [
          {
            "node": "Prepare Questions for API call",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Prompt and Model": {
      "main": [
        [
          {
            "node": "HTTP Request to Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request to Gemini": {
      "main": [
        [
          {
            "node": "If: Was an error detected?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redirect to Google Form": {
      "main": [
        []
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Extract JSON",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Extract JSON",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "If: Was an error detected?": {
      "main": [
        [
          {
            "node": "Set Fields: Define Outcome",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Fields: Define Outcome": {
      "main": [
        [
          {
            "node": "Extract JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Questions for API call": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 文档提取, 多模态 AI

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流