{
  "name": "AI Pexels Image Search and Google Drive Archive",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        0
      ],
      "id": "06369ce5-0a0a-465e-af7c-06240ca936f5",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "You are a helpful assistant that takes user input from text and search that image using pexels API in HTTP request tool.also show image in chat"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        272,
        -32
      ],
      "id": "3c4e82f0-1962-4956-83fc-585b2912d2e9",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "gpt-4o"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        80,
        208
      ],
      "id": "a48541e6-6324-4677-83f2-e16744c83999",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "https://api.pexels.com/v1/search",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ $json.chatInput }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "authorization",
              "value": "REPLACE_WITH_PEXELS_API_KEY"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequestTool",
      "typeVersion": 4.4,
      "position": [
        368,
        208
      ],
      "id": "92597b12-53eb-4070-9b5c-6d566d8f525d",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_SPREADSHEET_ID",
          "mode": "list",
          "cachedResultName": "Configure resource after import",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_SPREADSHEET_ID/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_SPREADSHEET_ID/edit#gid=0"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {
            "Query": "={{ $('When chat message received').item.json.chatInput }}",
            "link": "={{ $json.link }}"
          },
          "matchingColumns": [
            "Query"
          ],
          "schema": [
            {
              "id": "Query",
              "displayName": "Query",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "link",
              "displayName": "link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        2096,
        336
      ],
      "id": "32d5b633-1359-4d43-8be7-92805e90d6dd",
      "name": "Append or update row in sheet"
    },
    {
      "parameters": {
        "instructions": "Seprate the links",
        "codeGeneratedForPrompt": "Seprate the links",
        "jsCode": "const items = $input.all();\nconst output = items[0]?.json?.output;\nconst links = output\n  .match(/!\\[.*?\\]\\((.*?)\\)/g)\n  .map((link) => link.match(/\\((.*?)\\)/)[1]);\nreturn links.map((link) => ({ json: { link } }));\n"
      },
      "type": "n8n-nodes-base.aiTransform",
      "typeVersion": 1,
      "position": [
        704,
        144
      ],
      "id": "059ad4e0-a019-45cd-b575-d14e7254d193",
      "name": "AI Transform"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        912,
        144
      ],
      "id": "313b82aa-c0be-4576-88f5-4879ad1bee6c",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "url": "={{ $json.link }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1120,
        352
      ],
      "id": "f5d58942-f010-4e66-97d0-79b78a4f0430",
      "name": "HTTP Request1"
    },
    {
      "parameters": {
        "name": "={{ $('When chat message received').item.json.chatInput }}",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list",
          "cachedResultName": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive"
        },
        "folderId": {
          "__rl": true,
          "value": "REPLACE_WITH_GOOGLE_DRIVE_FOLDER_ID",
          "mode": "list",
          "cachedResultName": "Configure folder after import",
          "cachedResultUrl": "https://drive.google.com/drive/folders/REPLACE_WITH_GOOGLE_DRIVE_FOLDER_ID"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1488,
        64
      ],
      "id": "1acfb3ca-81e7-431d-a829-715bc27ca69c",
      "name": "Upload file"
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "AI Transform",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Transform": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "nodeGroups": [],
  "tags": []
}