{
  "name": "crAIzy chAIns · SOULREADERPLAY",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "49cf6609-ad34-4750-a9aa-835ff5ed76b2",
              "name": "seed_script",
              "value": "={{ $json.chatInput }}",
              "type": "string"
            },
            {
              "id": "b53d8ec2-6279-4972-8529-cca715a38e00",
              "name": "loop_index",
              "value": 0,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -16,
        -16
      ],
      "id": "b5e030cd-1f56-482e-84eb-e288b0a7104a",
      "name": "Seed input"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Extrahiere aus dem folgenden Text GENAU 5 deutsche Substantive (einzelne Wörter).\nKeine Eigennamen, keine Verben, keine Adjektive.\n\nAntworte NUR als gültiges JSON in genau diesem Format:\n{\"nouns\":[\"Wort1\",\"Wort2\",\"Wort3\",\"Wort4\",\"Wort5\"]}\n\nText:\n{{$json.seed_script}}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        192,
        -16
      ],
      "id": "c25409db-c96d-437f-a5bb-c25cf9f779c7",
      "name": "Basic LLM Chain"
    },
    {
      "parameters": {
        "jsCode": "let raw = ($json.text || \"\").trim();\n\n// entfernt ```json ... ``` oder auch ``json ... ``\nraw = raw\n  .replace(/^```json\\s*/i, \"\")\n  .replace(/^```/i, \"\")\n  .replace(/^``json\\s*/i, \"\")\n  .replace(/^``/i, \"\")\n  .replace(/```$/i, \"\")\n  .replace(/``$/i, \"\")\n  .trim();\n\nconst parsed = JSON.parse(raw);\nconst nouns = parsed.nouns || [];\n\nif (!Array.isArray(nouns) || nouns.length === 0) {\n  throw new Error(\"Keine nouns gefunden. LLM Output war: \" + raw);\n}\n\nreturn nouns.map((noun, i) => ({\n  json: {\n    noun,\n    noun_index: i,\n    seed_script: $json.seed_script,\n    loop_index: $json.loop_index\n  }\n}));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        544,
        -16
      ],
      "id": "85c73097-e12e-4bec-b0c7-583e3dfb0f9e",
      "name": "Nouns to items"
    },
    {
      "parameters": {
        "url": "https://api.pexels.com/v1/search",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{$json.noun}}"
            },
            {
              "name": "per_page",
              "value": "1"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "YOUR_PEXELS_API_KEY"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        752,
        -16
      ],
      "id": "479cafc1-0b62-4bf2-94e8-c9926530dda5",
      "name": "Pexels",
      "notes": "⚙️ SETUP: Header „Authorization“ = eigener Pexels-API-Key (pexels.com/api, kostenlos).",
      "notesInFlow": true
    },
    {
      "parameters": {
        "url": "={{$json.photos[0].src.large}}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "image"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        960,
        -16
      ],
      "id": "cd041a2a-7b13-4051-9b79-fcba1a16320e",
      "name": "Download Image"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        1184,
        -16
      ],
      "id": "8d8c71a5-354a-4bb5-a6d8-983e1a4cfefb",
      "name": "Batch 1-by-1"
    },
    {
      "parameters": {
        "jsCode": "const images = items.map(it => ({\n  noun: it.json.noun,\n  noun_index: it.json.noun_index,\n  url: it.json.photos?.[0]?.src?.large,\n  brightness: it.json.brightness,\n  mood: it.json.mood,\n  philosophy: it.json.philosophy,\n  tags: it.json.tags || []\n}));\n\nconst avgBrightness =\n  images.reduce((sum, x) => sum + (x.brightness ?? 5), 0) / images.length;\n\nconst moodCounts = images.reduce((acc, x) => {\n  acc[x.mood] = (acc[x.mood] || 0) + 1;\n  return acc;\n}, {});\n\nreturn [{\n  json: {\n    seed_script: items[0].json.seed_script,\n    loop_index: items[0].json.loop_index,\n    images,\n    avgBrightness,\n    moodCounts\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1472,
        -320
      ],
      "id": "d7dcff6d-46ee-478b-b5ae-39ce8c2718d9",
      "name": "Aggregate Results (Code"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "Schreibe ALLES auf DEUTSCH.\nDu bekommst 5 Bilder (Stimmung, Helligkeit, Tags, Philosophie pro Bild).\nErstelle eine emotionale Matrix, die die 5 Bilder als zusammenhängende Idee interpretiert.\n\nGib NUR gültiges JSON zurück:\n\n{\n  \"headline\": \"Kurzer poetischer Titel (Deutsch)\",\n  \"thesis\": \"1-2 Sätze auf Deutsch: Was verbindet diese 5 Bilder?\",\n  \"matrix\": [\n    {\n      \"image_index\": 0,\n      \"dominant_emotion\": \"1 deutsches Wort\",\n      \"brightness\": 0-10,\n      \"philosophical_note\": \"1 Satz auf Deutsch\"\n    }\n  ],\n  \"overall_tone\": \"positive|neutral|dark\",\n  \"writing_prompt\": \"1 deutscher Satz: Wie soll der nächste Text geschrieben werden (Genre + Stil)?\"\n}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        1680,
        -320
      ],
      "id": "6b2a5505-2015-4fc6-9514-8ed2ff29b2d3",
      "name": "Basic LLM Chain1"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "Schreibe einen kurzen Beitrag auf DEUTSCH (120–180 Wörter).\nNutze die emotionale Matrix als Regieanweisung.\nDer Text soll eigenständig funktionieren, auch wenn er banal wirkt.\n\nStilvorgabe (aus der Matrix):\n{{$json.writing_prompt}}\n\nNutze diese Bild-Infos als Inspiration:\n{{ JSON.stringify($json.images) }}\n\nGib NUR den Text zurück (kein JSON, keine Überschriften).",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        2032,
        -320
      ],
      "id": "1cecec7f-1e90-4b4a-9676-3e3434f8ea22",
      "name": "Write Next Text"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Schreibe aus dem folgenden Beitrag ein gesprochenes Skript auf DEUTSCH.\nDauer ca. 45–70 Sekunden.\nKurzes Intro + klarer Schluss.\nKeine Zeitmarken, keine Musik, keine Regieanweisungen.\n\nBEITRAG:\n{{$json.post_text}}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        2544,
        -320
      ],
      "id": "d552db88-7d68-4603-91c9-9d0f2c57a098",
      "name": "Script Writer Final"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "bcc777b0-29f8-4279-8da9-4f66bd0735fc",
              "name": "script_text",
              "value": "={{$json.text}}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2944,
        -320
      ],
      "id": "4e1bdb5f-cb5d-4f0d-af65-7e5f9ae42a0a",
      "name": "Save Script"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b1bc1804-e22b-4d43-9725-1ed70f98cf0a",
              "name": "post_text",
              "value": "={{$json.text}}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2304,
        -320
      ],
      "id": "4f064d5a-df63-43b6-b0a5-f9ccb53a53c4",
      "name": "Save Post Text"
    },
    {
      "parameters": {
        "jsCode": "// Erwartet Binary: image (von Download Image)\nif (!$binary?.image?.data) {\n  throw new Error(\"Kein Binary.image gefunden. Prüfe Download Image Node.\");\n}\n\nconst buf = Buffer.from($binary.image.data, 'base64');\n\n// Schneller Helligkeits-Proxy: Durchschnitt über Byte-Samples\nlet sum = 0;\nconst step = Math.max(1, Math.floor(buf.length / 20000)); // ~20k Samples\nlet count = 0;\n\nfor (let i = 0; i < buf.length; i += step) {\n  sum += buf[i];\n  count++;\n}\n\nconst avg = sum / count;           // 0..255\nconst brightness = Math.round((avg / 255) * 10); // 0..10\n\nlet mood = \"neutral\";\nif (brightness >= 7) mood = \"positive\";\nif (brightness <= 3) mood = \"dark\";\n\nconst philosophy =\n  mood === \"positive\"\n    ? \"Das Licht wirkt wie eine Einladung, die Welt für einen Moment leichter zu nehmen.\"\n    : mood === \"dark\"\n      ? \"Im Dunkel liegt keine Antwort – aber oft die ehrlichste Frage.\"\n      : \"Neutralität ist der Zwischenraum, in dem Bedeutung erst entsteht.\";\n\nreturn [{\n  json: {\n    ...$json,\n    brightness,\n    mood,\n    philosophy,\n    tags: [$json.noun || \"bild\", mood]\n  },\n  binary: $binary\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1616,
        272
      ],
      "id": "4f5961d1-95fd-4a5f-be9e-f854d6b754a8",
      "name": "Compute Brightness",
      "disabled": true
    },
    {
      "parameters": {
        "jsCode": "if (!$binary) throw new Error(\"Kein $binary vorhanden.\");\nconst keys = Object.keys($binary);\nif (keys.length === 0) throw new Error(\"Kein Binary gefunden.\");\n\nconst key = keys[0];\nconst bin = $binary[key];\nif (!bin?.data) throw new Error(⁠ Binary '${key}' hat keine data. Keys: ${keys.join(\", \")} ⁠);\n\nconst buf = Buffer.from(bin.data, 'base64');\n\nlet sum = 0;\nconst step = Math.max(1, Math.floor(buf.length / 20000));\nlet count = 0;\n\nfor (let i = 0; i < buf.length; i += step) { sum += buf[i]; count++; }\n\nconst avg = sum / count;           // 0..255\nconst brightness = Math.round((avg / 255) * 10);\n\nlet mood = \"neutral\";\nif (brightness >= 7) mood = \"positive\";\nif (brightness <= 3) mood = \"dark\";\n\nreturn [{\n  json: { ...$json, binary_key_used: key, brightness, mood },\n  binary: $binary\n}];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1456,
        400
      ],
      "id": "06568c1f-db1e-4971-a87a-cac5e5b7d41c",
      "name": "Compute Brightness1"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        192,
        176
      ],
      "id": "896457be-fabb-4a1e-b8a5-7e25d886d768",
      "name": "Google Gemini Chat Model",
      "notes": "⚙️ SETUP: Credential „Google Gemini (PaLM) API“ anlegen (Key: aistudio.google.com). Modell ggf. auf ein aktuelles Flash-Modell stellen.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        1616,
        -112
      ],
      "id": "b631a2d7-35b3-4809-9918-0547e83e0a20",
      "name": "Google Gemini Chat Model1",
      "notes": "⚙️ SETUP: Credential „Google Gemini (PaLM) API“ anlegen (Key: aistudio.google.com). Modell ggf. auf ein aktuelles Flash-Modell stellen.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        1968,
        -112
      ],
      "id": "2bd09c86-9c9d-4c40-a081-c1b85ed3e4d2",
      "name": "Google Gemini Chat Model2",
      "notes": "⚙️ SETUP: Credential „Google Gemini (PaLM) API“ anlegen (Key: aistudio.google.com). Modell ggf. auf ein aktuelles Flash-Modell stellen.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        2480,
        -112
      ],
      "id": "11f66c58-2cc4-4182-95e4-e28152af8794",
      "name": "Google Gemini Chat Model3",
      "notes": "⚙️ SETUP: Credential „Google Gemini (PaLM) API“ anlegen (Key: aistudio.google.com). Modell ggf. auf ein aktuelles Flash-Modell stellen.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        -240,
        -64
      ],
      "id": "62d69137-0a6b-436a-8db6-a2774f3da515",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "craizy-soulreaderplay",
        "responseMode": "lastNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -320,
        128
      ],
      "id": "17dc664a-d07c-45c8-ae83-6a4c7e11778e",
      "name": "loop-input",
      "webhookId": "84a9440e-d9cf-404d-8a4b-478391e8b9ca"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        3184,
        -320
      ],
      "id": "bd93b3bb-0cce-4f7b-a0d1-c429e7c4a258",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "content": "## 🔗 crAIzy chAIns – Archiv\n\n# SOULREADERPLAY\n\n**Team:** SOULREADER\n**Crazy-Level:** completely crAIzy, more than you'd expect\n\n> Aus einem Text werden 5 Nomen, aus Nomen Bilder, aus Bildern Helligkeit & Stimmung – und daraus ein neuer Text. Endlos.\n\nEntstanden im Seminar *crAIzy chAIns* (UdK Berlin, WiSe 2025/26). Gebaut als **agentische Rube-Goldberg-Maschine**: nicht effizient, sondern absichtlich verschlungen. Modelle & Prompts sind Stand 2025/26 – **kein Produktiv-Template, sondern ein Spielzeug**.\n\n### Setup-Checkliste\n- **Pexels** – Header „Authorization“ = eigener Pexels-API-Key (pexels\n- **Google Gemini Chat Model** – Credential „Google Gemini (PaLM) API“ anlegen (Key: aistudio\n\nAlle Stellen sind im Canvas mit **⚙️ SETUP** markiert. Es sind keine Zugangsdaten enthalten.\n\ncraizy.studio",
        "height": 720,
        "width": 680,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1080,
        -360
      ],
      "id": "16a9a3e5-5816-4e07-8ab1-94611f5db3eb",
      "name": "README crAIzy chAIns"
    }
  ],
  "connections": {
    "Seed input": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Nouns to items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nouns to items": {
      "main": [
        [
          {
            "node": "Pexels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pexels": {
      "main": [
        [
          {
            "node": "Download Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image": {
      "main": [
        [
          {
            "node": "Batch 1-by-1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Batch 1-by-1": {
      "main": [
        [
          {
            "node": "Aggregate Results (Code",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Compute Brightness",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Results (Code": {
      "main": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain1": {
      "main": [
        [
          {
            "node": "Write Next Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Next Text": {
      "main": [
        [
          {
            "node": "Save Post Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Script Writer Final": {
      "main": [
        [
          {
            "node": "Save Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Script": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Post Text": {
      "main": [
        [
          {
            "node": "Script Writer Final",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute Brightness": {
      "main": [
        [
          {
            "node": "Batch 1-by-1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Write Next Text",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Script Writer Final",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Seed input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "loop-input": {
      "main": [
        [
          {
            "node": "Seed input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [],
  "active": false
}