8
n8n 中文网amn8n.com

AI驱动的GPT-4-Turbo作业评分与多格式输出

中级

这是一个Document Extraction, AI Summarization领域的自动化工作流,包含 15 个节点。主要使用 Set, Code, Webhook, ConvertToFile, Agent 等节点。 使用GPT-4-Turbo自动化作业评分并生成多格式报告

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "jZ83o0HlyE8wjTR7",
  "meta": {
    "instanceId": "b91e510ebae4127f953fd2f5f8d40d58ca1e71c746d4500c12ae86aad04c1502",
    "templateCredsSetupCompleted": true
  },
  "name": "AI 驱动的 GPT-4-Turbo 作业评分与多格式输出",
  "tags": [],
  "nodes": [
    {
      "id": "31e0cb5c-e843-4c3e-b34d-b3adf5d38d54",
      "name": "Webhook - 上传试卷",
      "type": "n8n-nodes-base.webhook",
      "position": [
        128,
        -144
      ],
      "webhookId": "a98c19ae-7d0f-43ee-aa09-df8f4f5b0e1d",
      "parameters": {
        "path": "grade-assignment",
        "options": {
          "rawBody": true
        },
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "f103dd78-faf1-4ee4-a9af-d3350f1c7831",
      "name": "从试卷提取文本",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        352,
        -144
      ],
      "parameters": {
        "operation": "toText"
      },
      "typeVersion": 1
    },
    {
      "id": "b963d88c-cc9d-460a-8b80-f04ba04953e7",
      "name": "准备作业数据",
      "type": "n8n-nodes-base.set",
      "position": [
        576,
        -144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "studentName",
              "name": "studentName",
              "type": "string",
              "value": "={{ $json.body.studentName || 'Unknown Student' }}"
            },
            {
              "id": "assignmentTitle",
              "name": "assignmentTitle",
              "type": "string",
              "value": "={{ $json.body.assignmentTitle || 'Engineering Assignment' }}"
            },
            {
              "id": "testPaperText",
              "name": "testPaperText",
              "type": "string",
              "value": "={{ $('Extract Text from Test Paper').item.json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f1fce13f-f81c-43d7-94d0-9f4ebeb9994b",
      "name": "加载答案脚本",
      "type": "n8n-nodes-base.set",
      "position": [
        720,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "answerScript",
              "name": "answerScript",
              "type": "string",
              "value": "=Question 1: Explain Ohm's Law and its applications (10 marks)\nAnswer: Ohm's Law states V=IR where V is voltage, I is current, R is resistance. Applications include circuit design, electrical troubleshooting, power calculations.\n\nQuestion 2: Describe the working principle of a DC motor (15 marks)\nAnswer: DC motor converts electrical energy to mechanical energy using electromagnetic induction. Current through armature creates magnetic field that interacts with stator field causing rotation.\n\nQuestion 3: Calculate stress in a beam under load (20 marks)\nAnswer: Stress = Force/Area. For bending stress: σ = My/I where M is moment, y is distance from neutral axis, I is moment of inertia.\n\nQuestion 4: Explain thermodynamic cycles (15 marks)\nAnswer: Common cycles include Carnot, Otto, Diesel, Rankine. Each involves heat addition, expansion, heat rejection, compression stages for energy conversion.\n\nQuestion 5: Discuss Boolean algebra and logic gates (10 marks)\nAnswer: Boolean algebra uses AND, OR, NOT operations. Logic gates implement these: AND gate outputs 1 only when all inputs are 1, OR gate outputs 1 when any input is 1."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8877e50a-d8cc-42be-8592-6f91979861ea",
      "name": "AI 代理 - 评分作业",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        864,
        0
      ],
      "parameters": {
        "text": "=You are an expert engineering professor grading student assignments. \n\nANSWER SCRIPT (Correct Answers with Marks):\n{{ $json.answerScript }}\n\nSTUDENT SUBMISSION:\n{{ $json.testPaperText }}\n\nGrade this engineering assignment by:\n1. Comparing student answers against the answer script\n2. Award marks based on correctness, completeness, and technical accuracy\n3. Provide detailed feedback for each question\n4. Calculate total marks obtained\n\nProvide output in this JSON format:\n{\n  \"questions\": [\n    {\n      \"questionNumber\": 1,\n      \"maxMarks\": 10,\n      \"marksObtained\": 8,\n      \"feedback\": \"Good explanation of Ohm's Law but missing practical examples\"\n    }\n  ],\n  \"totalMarks\": 70,\n  \"totalObtained\": 55,\n  \"percentage\": 78.57,\n  \"grade\": \"B+\",\n  \"overallFeedback\": \"Strong understanding of core concepts with room for improvement in practical applications\"\n}",
        "options": {
          "systemMessage": "You are a precise grading assistant. Always return valid JSON only."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "c31a1abe-1b74-4c92-b391-14fd677337f1",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        832,
        224
      ],
      "parameters": {
        "model": "gpt-4-turbo",
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "OGYj7DgYv5GFLFZk",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5abe696d-6ca7-48ac-8e60-cf6ea12ccba0",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1024,
        224
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "a54dc27f-f275-4ef7-b70d-06e0b9958ff1",
      "name": "生成结果表格",
      "type": "n8n-nodes-base.code",
      "position": [
        1152,
        0
      ],
      "parameters": {
        "jsCode": "const gradingResult = $input.first().json;\nconst studentName = $('Prepare Assignment Data').first().json.studentName;\nconst assignmentTitle = $('Prepare Assignment Data').first().json.assignmentTitle;\n\n// Create HTML table\nlet htmlTable = `\n<h2>Grading Report: ${assignmentTitle}</h2>\n<h3>Student: ${studentName}</h3>\n<table border=\"1\" cellpadding=\"10\" cellspacing=\"0\" style=\"border-collapse: collapse; width: 100%;\">\n  <thead>\n    <tr style=\"background-color: #4CAF50; color: white;\">\n      <th>Question</th>\n      <th>Max Marks</th>\n      <th>Marks Obtained</th>\n      <th>Feedback</th>\n    </tr>\n  </thead>\n  <tbody>\n`;\n\ngradingResult.questions.forEach(q => {\n  htmlTable += `\n    <tr>\n      <td>Question ${q.questionNumber}</td>\n      <td>${q.maxMarks}</td>\n      <td>${q.marksObtained}</td>\n      <td>${q.feedback}</td>\n    </tr>\n  `;\n});\n\nhtmlTable += `\n  </tbody>\n  <tfoot>\n    <tr style=\"background-color: #f2f2f2; font-weight: bold;\">\n      <td>TOTAL</td>\n      <td>${gradingResult.totalMarks}</td>\n      <td>${gradingResult.totalObtained}</td>\n      <td>Grade: ${gradingResult.grade} (${gradingResult.percentage.toFixed(2)}%)</td>\n    </tr>\n  </tfoot>\n</table>\n<p><strong>Overall Feedback:</strong> ${gradingResult.overallFeedback}</p>\n`;\n\n// Create CSV data\nlet csvData = \"Question,Max Marks,Marks Obtained,Feedback\\n\";\ngradingResult.questions.forEach(q => {\n  csvData += `\"Question ${q.questionNumber}\",${q.maxMarks},${q.marksObtained},\"${q.feedback.replace(/\"/g, '\"\"')}\"\\n`;\n});\ncsvData += `\"TOTAL\",${gradingResult.totalMarks},${gradingResult.totalObtained},\"Grade: ${gradingResult.grade} (${gradingResult.percentage.toFixed(2)}%)\"\\n`;\n\nreturn {\n  studentName,\n  assignmentTitle,\n  htmlTable,\n  csvData,\n  gradingResult,\n  summary: `${studentName} scored ${gradingResult.totalObtained}/${gradingResult.totalMarks} (${gradingResult.percentage.toFixed(2)}%) - Grade: ${gradingResult.grade}`\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "cea0caf8-7c57-4a2b-ad16-afc77130cb52",
      "name": "转换为 HTML 文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        1376,
        -192
      ],
      "parameters": {
        "operation": "text"
      },
      "typeVersion": 1.1
    },
    {
      "id": "db26bad8-9732-4cac-b320-6ec74769994e",
      "name": "转换为 CSV 文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        1600,
        0
      ],
      "parameters": {
        "operation": "text"
      },
      "typeVersion": 1.1
    },
    {
      "id": "f4acb791-f4e0-49e3-9402-b09e6e721411",
      "name": "准备 CSV 数据",
      "type": "n8n-nodes-base.set",
      "position": [
        1376,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "data",
              "name": "data",
              "type": "string",
              "value": "={{ $('Generate Results Table').first().json.csvData }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7b2f31c8-620b-4e86-8c67-6762de1c25d9",
      "name": "响应 Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1600,
        192
      ],
      "parameters": {
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        },
        "respondWith": "allIncomingItems"
      },
      "typeVersion": 1.1
    },
    {
      "id": "70b0f767-fe68-41f4-92ff-b12592a85e9a",
      "name": "格式化响应",
      "type": "n8n-nodes-base.set",
      "position": [
        1376,
        192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "status",
              "name": "status",
              "type": "string",
              "value": "success"
            },
            {
              "id": "message",
              "name": "message",
              "type": "string",
              "value": "={{ $('Generate Results Table').first().json.summary }}"
            },
            {
              "id": "results",
              "name": "results",
              "type": "object",
              "value": "={{ $('Generate Results Table').first().json.gradingResult }}"
            },
            {
              "id": "htmlReport",
              "name": "htmlReport",
              "type": "string",
              "value": "={{ $('Generate Results Table').first().json.htmlTable }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4903bfe6-d63b-47e0-b8a2-27a3ee94b0fe",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -192
      ],
      "parameters": {
        "width": 624,
        "height": 560,
        "content": "## 介绍"
      },
      "typeVersion": 1
    },
    {
      "id": "6a1ddb69-1170-4be7-b121-77f705304ee1",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        32
      ],
      "parameters": {
        "color": 3,
        "width": 336,
        "height": 448,
        "content": "## 先决条件"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7e3e4fd2-236b-4ffa-ac24-5fdd3e7b2b70",
  "connections": {
    "Format Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare CSV Data": {
      "main": [
        [
          {
            "node": "Convert to CSV File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Grade Assignment",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Load Answer Script": {
      "main": [
        [
          {
            "node": "AI Agent - Grade Assignment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Results Table": {
      "main": [
        [
          {
            "node": "Convert to HTML File",
            "type": "main",
            "index": 0
          },
          {
            "node": "Prepare CSV Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Assignment Data": {
      "main": [
        [
          {
            "node": "Load Answer Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent - Grade Assignment",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent - Grade Assignment": {
      "main": [
        [
          {
            "node": "Generate Results Table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook - Upload Test Paper": {
      "main": [
        [
          {
            "node": "Extract Text from Test Paper",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from Test Paper": {
      "main": [
        [
          {
            "node": "Prepare Assignment Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 文档提取, AI 摘要总结

需要付费吗?

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

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

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

作者
Cheng Siong Chin

Cheng Siong Chin

@cschin

Prof. Cheng Siong CHIN serves as Chair Professor in Intelligent Systems Modelling and Simulation in Newcastle University, Singapore. His academic credentials include an M.Sc. in Advanced Control and Systems Engineering from The University of Manchester and a Ph.D. in Robotics from Nanyang Technological University.

外部链接
在 n8n.io 查看

分享此工作流