{
  "id": "ft-data-collect-07",
  "meta": {
    "instanceId": "vorlux-hub"
  },
  "name": "Vorlux AI | Fine-Tune Data Collector (Daily 2am)",
  "active": true,
  "nodes": [
    {
      "id": "a7b8c9d0-0007-4aaa-8007-000000000001",
      "name": "Daily 2am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [220, 300],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      }
    },
    {
      "id": "a7b8c9d0-0007-4aaa-8007-000000000002",
      "name": "Fetch Agent Executions",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 150],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/admin/agent-memory?type=execution&quality_min=5&limit=100&since=24h",
        "options": {
          "timeout": 30000
        }
      },
      "notes": "Gets recent high-quality agent executions from agent_memory table"
    },
    {
      "id": "a7b8c9d0-0007-4aaa-8007-000000000003",
      "name": "Fetch Content Projects",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 350],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/content/pipeline?status=published&limit=50&since=24h",
        "options": {
          "timeout": 15000
        }
      },
      "notes": "Gets recently published content projects (successful pipeline outputs)"
    },
    {
      "id": "a7b8c9d0-0007-4aaa-8007-000000000004",
      "name": "Fetch Workflow Executions",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 550],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/admin/n8n/executions?status=success&limit=50&since=24h",
        "options": {
          "timeout": 15000
        }
      },
      "notes": "Gets recent successful n8n workflow executions"
    },
    {
      "id": "a7b8c9d0-0007-4aaa-8007-000000000005",
      "name": "Format as Alpaca Pairs",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [740, 300],
      "notes": "Converts all collected data into instruction/output training pairs (Alpaca format)",
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const agentExecs = $('Fetch Agent Executions').first().json.data || [];\nconst contentProjects = $('Fetch Content Projects').first().json.data || [];\nconst wfExecs = $('Fetch Workflow Executions').first().json.data || [];\n\nconst examples = [];\n\n// Agent execution examples\nfor (const exec of agentExecs) {\n  if (!exec.prompt || !exec.result) continue;\n  examples.push({\n    instruction: exec.prompt.substring(0, 2000),\n    input: exec.context ? JSON.stringify(exec.context).substring(0, 500) : '',\n    output: (typeof exec.result === 'string' ? exec.result : JSON.stringify(exec.result)).substring(0, 4000),\n    source: 'agent_execution',\n    agent: exec.agent_id || 'unknown',\n    quality: exec.quality_score || 5\n  });\n}\n\n// Content project examples\nfor (const cp of contentProjects) {\n  if (!cp.title || !cp.content) continue;\n  // Variant 1: Create content\n  examples.push({\n    instruction: `Create a ${cp.content_type || 'blog'} post about: ${cp.title}`,\n    input: cp.source_description || '',\n    output: cp.content.substring(0, 4000),\n    source: 'content_project',\n    quality: 7\n  });\n  // Variant 2: Generate SEO\n  if (cp.seo_data) {\n    examples.push({\n      instruction: `Generate SEO metadata for a blog post titled: ${cp.title}`,\n      input: '',\n      output: typeof cp.seo_data === 'string' ? cp.seo_data : JSON.stringify(cp.seo_data),\n      source: 'content_seo',\n      quality: 6\n    });\n  }\n}\n\n// Workflow execution examples\nfor (const wf of wfExecs) {\n  if (!wf.name || !wf.nodes) continue;\n  examples.push({\n    instruction: `Create an n8n workflow for: ${wf.name.replace('Vorlux AI | ', '')}`,\n    input: '',\n    output: JSON.stringify({ nodes: wf.nodes, connections: wf.connections || {} }).substring(0, 8000),\n    source: 'workflow_execution',\n    quality: 8\n  });\n}\n\nreturn [{ json: { examples, count: examples.length, breakdown: { agent: agentExecs.length, content: contentProjects.length, workflow: wfExecs.length } } }];"
      }
    },
    {
      "id": "a7b8c9d0-0007-4aaa-8007-000000000006",
      "name": "Append to Training File",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1000, 200],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/admin/finetune/append",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ examples: $json.examples, targetFile: 'combined-finetune.jsonl' }) }}",
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "a7b8c9d0-0007-4aaa-8007-000000000007",
      "name": "Discord Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1000, 400],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"Fine-Tune Data Collector\",\"description\":\"Collected {{ $json.count }} new training examples\\n\\nBreakdown:\\n- Agent executions: {{ $json.breakdown.agent }}\\n- Content projects: {{ $json.breakdown.content }}\\n- Workflow executions: {{ $json.breakdown.workflow }}\",\"color\":10181046,\"footer\":{\"text\":\"Daily 2am - Fine-Tune Data Collector\"}}]}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Daily 2am": {
      "main": [
        [
          {
            "node": "Fetch Agent Executions",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Content Projects",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Workflow Executions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Agent Executions": {
      "main": [
        [
          {
            "node": "Format as Alpaca Pairs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Content Projects": {
      "main": [
        [
          {
            "node": "Format as Alpaca Pairs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Workflow Executions": {
      "main": [
        [
          {
            "node": "Format as Alpaca Pairs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format as Alpaca Pairs": {
      "main": [
        [
          {
            "node": "Append to Training File",
            "type": "main",
            "index": 0
          },
          {
            "node": "Discord Notify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  },
  "tags": [
    { "name": "ai" },
    { "name": "finetune" },
    { "name": "training" },
    { "name": "data" }
  ],
  "versionId": "2"
}