{
  "id": "a8f3c2e1-4b5d-4a6e-9c7f-1d2e3f4a5b6c",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "name": "PromptPerfect \u2014 Optimize Prompt",
  "tags": [
    {
      "name": "promptperfect"
    },
    {
      "name": "ai"
    },
    {
      "name": "prompt-optimization"
    }
  ],
  "nodes": [
    {
      "parameters": {},
      "id": "11111111-1111-4111-8111-111111111111",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "22222222-2222-4222-8222-222222222221",
              "name": "promptText",
              "value": "Explain quantum computing in simple terms",
              "type": "string"
            },
            {
              "id": "22222222-2222-4222-8222-222222222222",
              "name": "targetModel",
              "value": "chatgpt",
              "type": "string"
            },
            {
              "id": "22222222-2222-4222-8222-222222222223",
              "name": "apiKey",
              "value": "YOUR_API_KEY_HERE",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "22222222-2222-4222-8222-222222220002",
      "name": "Set Prompt Input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.promptperfect.jina.ai/api/optimize-sync",
        "authentication": "none",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "x-api-key",
              "value": "={{ $json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ data: { prompt: { text: $json.promptText }, targetModel: $json.targetModel, promptType: 'text' } }) }}",
        "options": {
          "timeout": 30000,
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "id": "33333333-3333-4333-8333-333333333333",
      "name": "Optimize Prompt",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const response = items[0].json;\n\nconst optimizedPrompt =\n  response?.result?.promptOptimized ||\n  response?.promptOptimized ||\n  'No result returned';\n\nconst input = $('Set Prompt Input').first().json;\n\nreturn [\n  {\n    json: {\n      original_prompt: input.promptText || '',\n      optimized_prompt: optimizedPrompt,\n      target_model: input.targetModel || 'chatgpt',\n      success:\n        !!optimizedPrompt && optimizedPrompt !== 'No result returned',\n      timestamp: new Date().toISOString(),\n    },\n  },\n];\n"
      },
      "id": "44444444-4444-4444-8444-444444444444",
      "name": "Extract Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Prompt Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Prompt Input": {
      "main": [
        [
          {
            "node": "Optimize Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Optimize Prompt": {
      "main": [
        [
          {
            "node": "Extract Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "triggerCount": 0,
  "versionId": "b9e4d3f2-5c6e-4b7f-ad8e-2f3a4b5c6d7e",
  "active": false
}