{
  "name": "Culinaize Chatbot",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "culinaize-chat",
        "responseMode": "responseNode",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        2336,
        464
      ],
      "id": "404c24e2-c1c5-4522-bd5e-edc7c977ec44"
    },
    {
      "parameters": {
        "jsCode": "const body = $input.first().json.body || {};\nconst headers = $input.first().json.headers || {};\nconst auth = headers.authorization || '';\nconst sessionId = auth ? auth.slice(-16) : 'guest-session';\n\nconst rawImage = body.image || null;\nconst jsonOut = {\n  sessionId,\n  chatInput: body.message || 'What can I cook with these ingredients?'\n};\n\nif (rawImage && rawImage.includes('base64,')) {\n  const parts = rawImage.split(';base64,');\n  const mimeType = parts[0].replace('data:', '');\n  const base64Data = parts[1];\n\n  return [{\n    json: jsonOut,\n    binary: {\n      data: {\n        data: base64Data,\n        mimeType: mimeType,\n        fileName: 'ingredients.jpg'\n      }\n    }\n  }];\n}\n\nreturn [{ json: jsonOut }];"
      },
      "name": "Prepare Payload & Binary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2576,
        464
      ],
      "id": "58f9dc05-9900-4ac4-9481-1c0a6ce8f8b3"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "You are Culinaize Chef, an expert culinary assistant.\n\n### SCOPE & ROLE:\n- You ONLY answer questions related to food, cooking, recipes, ingredients, meal prep, and kitchen techniques.\n- If an image is attached, inspect it carefully to identify ingredients and suggest delicious meals.\n- Always ground recipe recommendations in real Spoonacular recipe data and format answers in clean Markdown.\n\n### STRICT BOUNDARIES & REFUSALS:\n- If the user asks non-culinary questions (such as coding, math, medical diagnosis, politics, financial advice, or general trivia), POLITELY DECLINE.\n- Example refusal: 'I am Culinaize, your dedicated cooking assistant! I can only help with recipes, ingredients, and cooking techniques. What are we cooking today?'",
          "passthroughBinaryImages": true
        }
      },
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        2816,
        464
      ],
      "id": "ff7c8c72-c76e-4368-a3ed-36628f1c8ba1"
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.5-flash-lite",
        "options": {}
      },
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        2736,
        688
      ],
      "id": "b5308b11-4688-43b2-94f1-fbfa64b3dad0",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "contextWindowLength": 6
      },
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        2880,
        688
      ],
      "id": "aabacd87-1234-4896-aa32-46d82c7eb767"
    },
    {
      "parameters": {
        "toolDescription": "Search Spoonacular for recipes based on ingredients or food queries",
        "url": "https://api.spoonacular.com/recipes/complexSearch",
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {
              "name": "query"
            },
            {
              "name": "includeIngredients"
            },
            {
              "name": "addRecipeInformation"
            },
            {
              "name": "number"
            },
            {
              "name": "apiKey",
              "valueProvider": "fieldValue",
              "value": "{place_your_key_here}"
            }
          ]
        }
      },
      "name": "Spoonacular Tool",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        3040,
        688
      ],
      "id": "39716749-8528-4106-93fc-5ef56955b0fd"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"output\": {\n    \"text\": {{ JSON.stringify($json.output) }}\n  }\n}",
        "options": {}
      },
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        3184,
        464
      ],
      "id": "789a8135-30ca-40f5-b429-5dc06e97bdbc"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Prepare Payload & Binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Payload & Binary": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Spoonacular Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "c5cc2ece-41d3-4692-8c22-24bae077a35c",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodeGroups": [],
  "id": "9rJ1Sqp5awNMgcGO",
  "tags": []
}