{
  "name": "Frag das Dokument",
  "nodes": [
    {
      "parameters": {
        "authentication": "n8nUserAuth",
        "formTitle": "Frag das Dokument",
        "formDescription": "PDF hochladen, Frage stellen. Die Antwort stützt sich nur auf das Dokument.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Dokument",
              "fieldType": "file",
              "multipleFiles": false,
              "acceptFileTypes": ".pdf",
              "requiredField": true
            },
            {
              "fieldLabel": "Frage",
              "fieldType": "textarea",
              "requiredField": true
            }
          ]
        },
        "responseMode": "lastNode",
        "options": {
          "buttonLabel": "Fragen"
        }
      },
      "id": "dbb2f442-72c4-4c3f-8dae-fc016abf007f",
      "name": "Dokument und Frage",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.6,
      "position": [
        0,
        0
      ],
      "webhookId": "a26a0d3f-b632-4db8-8552-30f347729ed4"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://docling:5001/v1/convert/file",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "files",
              "inputDataFieldName": "Dokument"
            },
            {
              "name": "to_formats",
              "value": "md"
            },
            {
              "name": "to_formats",
              "value": "json"
            }
          ]
        },
        "options": {
          "timeout": 180000
        }
      },
      "id": "41f843ff-5bcb-4cd6-ae4d-6f1c2c99b6c6",
      "name": "Docling",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const d = $json.document;\n// Fußnoten und Text in Bildern stehen nur im JSON, nicht im Markdown\nconst ergaenzungen = d.json_content.texts\n  .filter(t => /^#\\/(tables|pictures)\\//.test(t.parent?.$ref ?? ''))\n  .map(t => '- ' + t.text);\nreturn { kontext: d.md_content + '\\n\\n## Ergänzungen (Fußnoten, Text in Bildern)\\n' + ergaenzungen.join('\\n') };"
      },
      "id": "4022ef06-de5d-4561-bcf7-8fc15c2932fc",
      "name": "Kontext bauen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Dokument:\n{{ $json.kontext }}\n\nFrage: {{ $('Dokument und Frage').item.json.Frage }}",
        "messages": {
          "messageValues": [
            {
              "message": "Beantworte die Frage nur mit Angaben aus dem Dokument. Wenn die Antwort nicht im Dokument steht, sag das. Nenne kurz die Stelle, auf die du dich stützt. Antworte in höchstens drei Sätzen, als einfacher Text ohne Markdown."
            }
          ]
        }
      },
      "id": "cd5e1519-c66e-4153-a8af-f74ca69feadb",
      "name": "Antwort",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        720,
        0
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "mistral/zai-glm-5-3"
        },
        "responsesApiEnabled": false,
        "options": {
          "temperature": 0
        }
      },
      "id": "c0f6ae74-4eed-430c-a980-15391ac7670c",
      "name": "GLM",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        720,
        220
      ]
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "text",
        "completionTitle": "Antwort",
        "completionMessage": "={{ $json.text }}",
        "options": {}
      },
      "id": "60a71fb3-26fa-4f43-96cf-a60d4dced600",
      "name": "Antwort zeigen",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [
        960,
        0
      ],
      "webhookId": "d123603a-1585-4ea8-a409-0830be18c3df"
    }
  ],
  "connections": {
    "Dokument und Frage": {
      "main": [
        [
          {
            "node": "Docling",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Docling": {
      "main": [
        [
          {
            "node": "Kontext bauen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kontext bauen": {
      "main": [
        [
          {
            "node": "Antwort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Antwort": {
      "main": [
        [
          {
            "node": "Antwort zeigen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GLM": {
      "ai_languageModel": [
        [
          {
            "node": "Antwort",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}
