{
  "name": "UFRO PP3 Orchestrator Workflow",
  "nodes": [
    {
      "parameters": {},
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://52.22.115.249:5000/verify",
        "authentication": "none",
        "options": {
          "bodyContentType": "multipart-form-data"
        },
        "bodyParameters": {
          "parameters": [
            {
              "name": "file",
              "value": "={{ $binary.data }}"
            }
          ]
        }
      },
      "id": "pp2-verify",
      "name": "PP2 Verify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-1",
              "leftValue": "={{ $json.verified }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            },
            {
              "id": "condition-2",
              "leftValue": "={{ $json.confidence }}",
              "rightValue": 0.75,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "check-threshold",
      "name": "Check Threshold",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://3.231.127.90:8081/",
        "authentication": "none",
        "contentType": "json",
        "bodyParametersJson": "={{ JSON.stringify({ message: $('Webhook Trigger').item.json.query, provider: 'deepseek', k: 4 }) }}"
      },
      "id": "pp1-ask",
      "name": "PP1 Ask",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        850,
        200
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "resource": "document",
        "database": "ufro",
        "collection": "traces",
        "fields": {
          "mappingMode": "defineBelow",
          "value": {
            "request_id": "={{ $('Webhook Trigger').item.json.request_id }}",
            "query": "={{ $('Webhook Trigger').item.json.query }}",
            "person_identified": "={{ $('Check Threshold').item.json.verified }}",
            "confidence": "={{ $('PP2 Verify').item.json.confidence }}",
            "answer": "={{ $('PP1 Ask').item.json.answer }}",
            "pp1_response": "={{ $('PP1 Ask').item.json }}",
            "pp2_response": "={{ $('PP2 Verify').item.json }}",
            "timestamp": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "save-trace",
      "name": "Save Trace to MongoDB",
      "type": "n8n-nodes-base.mongoDb",
      "typeVersion": 1,
      "position": [
        1050,
        200
      ],
      "credentials": {
        "mongoDb": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ person_identified: $('Check Threshold').item.json.verified, answer: $('PP1 Ask').item.json.answer, confidence: $('PP2 Verify').item.json.confidence }) }}"
      },
      "id": "respond",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1250,
        200
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ person_identified: false, answer: 'Persona no identificada', confidence: $('PP2 Verify').item.json.confidence }) }}"
      },
      "id": "respond-not-identified",
      "name": "Respond Not Identified",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        850,
        400
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "PP2 Verify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PP2 Verify": {
      "main": [
        [
          {
            "node": "Check Threshold",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Threshold": {
      "main": [
        [
          {
            "node": "PP1 Ask",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond Not Identified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PP1 Ask": {
      "main": [
        [
          {
            "node": "Save Trace to MongoDB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Trace to MongoDB": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2024-01-01T00:00:00.000Z",
  "versionId": "1"
}