[
    {
        "id": "8fbe661c97151225",
        "type": "tab",
        "label": "RapGPT",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "0369573cae1becfa",
        "type": "http in",
        "z": "8fbe661c97151225",
        "name": "",
        "url": "/webhooks/rap-gpt",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 170,
        "y": 140,
        "wires": [
            [
                "74529201bfed6cc9",
                "398399d9950ffbd5"
            ]
        ]
    },
    {
        "id": "49aa79107216750f",
        "type": "http response",
        "z": "8fbe661c97151225",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 630,
        "y": 300,
        "wires": []
    },
    {
        "id": "74529201bfed6cc9",
        "type": "change",
        "z": "8fbe661c97151225",
        "name": "Save ItemId",
        "rules": [
            {
                "t": "set",
                "p": "mimir.itemId",
                "pt": "msg",
                "to": "payload.items[0].id",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 140,
        "wires": [
            [
                "708d44b28a2581dd"
            ]
        ]
    },
    {
        "id": "06627888741580a8",
        "type": "switch",
        "z": "8fbe661c97151225",
        "name": "Check Transcript",
        "property": "mimir.output.payload.timedTranscriptUrl",
        "propertyType": "msg",
        "rules": [
            {
                "t": "null"
            },
            {
                "t": "nnull"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 160,
        "y": 300,
        "wires": [
            [
                "3cb6abad8d79f85e"
            ],
            [
                "853e46ba3ef309e8"
            ]
        ],
        "outputLabels": [
            "Error",
            "Success"
        ]
    },
    {
        "id": "86ab2066073bbb4c",
        "type": "http response",
        "z": "8fbe661c97151225",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 630,
        "y": 260,
        "wires": []
    },
    {
        "id": "853e46ba3ef309e8",
        "type": "change",
        "z": "8fbe661c97151225",
        "name": "Set Callback Payload",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"message\":\"Rap this Video\",\"status\":\"success\"}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 420,
        "y": 340,
        "wires": [
            [
                "f48a51ba19a44d33",
                "49aa79107216750f"
            ]
        ]
    },
    {
        "id": "3cb6abad8d79f85e",
        "type": "change",
        "z": "8fbe661c97151225",
        "name": "Set Callback Payload",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"message\":\"Transcript not found!\",\"status\":\"error\"}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 420,
        "y": 260,
        "wires": [
            [
                "86ab2066073bbb4c"
            ]
        ]
    },
    {
        "id": "5c582f3c71c846ee",
        "type": "function",
        "z": "8fbe661c97151225",
        "name": "Concatenate the Transcript",
        "func": "msg.mimir.transcript = msg.payload.map(item => item.content).join(' ');\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 900,
        "y": 340,
        "wires": [
            [
                "4590e60481a1f469"
            ]
        ]
    },
    {
        "id": "f48a51ba19a44d33",
        "type": "http request",
        "z": "8fbe661c97151225",
        "name": "Fetch Transcript",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "{{{mimir.output.payload.timedTranscriptUrl}}}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 660,
        "y": 340,
        "wires": [
            [
                "5c582f3c71c846ee"
            ]
        ]
    },
    {
        "id": "4590e60481a1f469",
        "type": "change",
        "z": "8fbe661c97151225",
        "name": "Set Prompts",
        "rules": [
            {
                "t": "set",
                "p": "openai.model",
                "pt": "msg",
                "to": "gpt-4o",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "openai.userPrompt",
                "pt": "msg",
                "to": "\"User Input: \\n\\n\" & mimir.transcript",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "openai.systemPrompt",
                "pt": "msg",
                "to": "You are RapperGPT, an AI that generates short creative rap verses based on the user's input. Your lyrics should be catchy, engaging, and follow a consistent rhyme scheme. Showcase your wordplay skills, and feel free to incorporate pop culture references, puns, and metaphors when appropriate.",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "openai.inputTokenPrice",
                "pt": "msg",
                "to": "0.000005",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "openai.outputTokenPrice",
                "pt": "msg",
                "to": "0.000015",
                "tot": "num"
            },
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "mimir.output",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "auth",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1130,
        "y": 340,
        "wires": [
            [
                "2095c96067df70a4"
            ]
        ]
    },
    {
        "id": "d638c9f3832a26e1",
        "type": "change",
        "z": "8fbe661c97151225",
        "name": "Save the Rap Rhymes",
        "rules": [
            {
                "t": "set",
                "p": "mimir.rapSummary",
                "pt": "msg",
                "to": "openai.output.payload.choices[0].message.content",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "price",
                "pt": "msg",
                "to": "\"$\" & (openai.inputTokenPrice * openai.output.payload.usage.prompt_tokens + openai.output.payload.usage.completion_tokens * openai.outputTokenPrice)",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "openai.usage",
                "pt": "msg",
                "to": "openai.output.payload.usage",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "openai.output",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 400,
        "y": 520,
        "wires": [
            [
                "5c77d1a3a177d5b3"
            ]
        ]
    },
    {
        "id": "aad729927acbdfc6",
        "type": "debug",
        "z": "8fbe661c97151225",
        "name": "Update Item Success",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "\"👍 \" & price ",
        "statusType": "jsonata",
        "x": 765,
        "y": 480,
        "wires": [],
        "icon": "font-awesome/fa-check-circle",
        "l": false
    },
    {
        "id": "29eb9c44a389b64c",
        "type": "debug",
        "z": "8fbe661c97151225",
        "name": "Update Item Error",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "counter",
        "x": 765,
        "y": 560,
        "wires": [],
        "icon": "font-awesome/fa-exclamation-triangle",
        "l": false
    },
    {
        "id": "e1d94d444cc18f58",
        "type": "debug",
        "z": "8fbe661c97151225",
        "name": "Rap Rhymes Error",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "counter",
        "x": 315,
        "y": 560,
        "wires": [],
        "icon": "font-awesome/fa-exclamation-triangle",
        "l": false
    },
    {
        "id": "17defa42c1ca6c99",
        "type": "debug",
        "z": "8fbe661c97151225",
        "name": "Fetch Item Data Error",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "counter",
        "x": 745,
        "y": 140,
        "wires": [],
        "icon": "font-awesome/fa-exclamation-triangle",
        "l": false
    },
    {
        "id": "398399d9950ffbd5",
        "type": "debug",
        "z": "8fbe661c97151225",
        "name": "Webhook Data",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "counter",
        "x": 375,
        "y": 80,
        "wires": [],
        "icon": "font-awesome/fa-info-circle",
        "l": false
    },
    {
        "id": "708d44b28a2581dd",
        "type": "mimir-api-client",
        "z": "8fbe661c97151225",
        "name": "Fetch Item Data",
        "selectedOperation": {
            "method": "get",
            "path": "/api/v1/items/{itemId}",
            "summary": "Retrieve an Item entry",
            "description": "Retrieve an item entry with specified identifier string\n",
            "tag": "Item",
            "operationId": "get_api_v1_items__itemId_"
        },
        "api": "api-0",
        "errorHandlingModeSelectedIndex": 1,
        "security": [
            {
                "id": "ApiKeyAuth",
                "type": "apiKey",
                "description": "",
                "name": "x-mimir-cognito-id-token",
                "in": "header"
            }
        ],
        "requestContentTypeSelectedIndex": 0,
        "responseContentTypeSelectedIndex": 0,
        "parameters": [
            {
                "name": "itemId",
                "value": "mimir.itemId",
                "in": "path",
                "refType": "msg"
            },
            {
                "name": "searchString",
                "value": "",
                "in": "query",
                "refType": "type"
            },
            {
                "name": "isFuzzy",
                "value": "",
                "in": "query",
                "refType": "type"
            },
            {
                "name": "readableMetadataFields",
                "value": "true",
                "in": "query",
                "refType": "type"
            },
            {
                "name": "fields",
                "value": "",
                "in": "query",
                "refType": "type"
            }
        ],
        "uiFeatures": {
            "operations": {
                "advancedMode": true
            }
        },
        "credentialValues": {
            "username": {
                "value": "",
                "type": "string",
                "refType": "type"
            },
            "password": {
                "value": "",
                "type": "string",
                "refType": "type"
            },
            "value": {
                "value": "\"Bearer \" & $globalContext(\"SECRETS.MIMIR_API_KEY\")",
                "type": "string",
                "refType": "jsonata"
            }
        },
        "outputs": 2,
        "output": "mimir.output",
        "host": {
            "type": "string",
            "value": "SECRETS.MIMIR_BASE_URL",
            "refType": "global"
        },
        "x": 580,
        "y": 140,
        "wires": [
            [
                "06627888741580a8"
            ],
            [
                "17defa42c1ca6c99"
            ]
        ]
    },
    {
        "id": "5c77d1a3a177d5b3",
        "type": "mimir-api-client",
        "z": "8fbe661c97151225",
        "name": "Update Item",
        "selectedOperation": {
            "method": "post",
            "path": "/api/v1/items/{itemId}",
            "summary": "Update an Item entry",
            "description": "Update an item entry with specified identifier string\n",
            "tag": "Item",
            "operationId": "post_api_v1_items__itemId_"
        },
        "api": "api-0",
        "errorHandlingModeSelectedIndex": 1,
        "security": [
            {
                "id": "ApiKeyAuth",
                "type": "apiKey",
                "description": "",
                "name": "x-mimir-cognito-id-token",
                "in": "header"
            }
        ],
        "requestContentTypeSelectedIndex": 0,
        "responseContentTypeSelectedIndex": 0,
        "parameters": [
            {
                "name": "itemId",
                "value": "mimir.itemId",
                "in": "path",
                "refType": "msg"
            },
            {
                "name": "readableMetadataFields",
                "value": "true",
                "in": "query",
                "refType": "type"
            },
            {
                "name": "requiredMetadataVersion",
                "value": "",
                "in": "query",
                "refType": "type"
            },
            {
                "name": "body",
                "value": "{\n   \"metadataDelta\": {\n       \"formData\": {\n           \"rapSummary\": mimir.rapSummary\n    }\n  }\n}",
                "in": "body",
                "refType": "jsonata"
            }
        ],
        "uiFeatures": {
            "operations": {
                "advancedMode": true
            }
        },
        "credentialValues": {
            "username": {
                "value": "",
                "type": "string",
                "refType": "type"
            },
            "password": {
                "value": "",
                "type": "string",
                "refType": "type"
            },
            "value": {
                "value": "\"Bearer \" & $globalContext(\"SECRETS.MIMIR_API_KEY\")",
                "type": "string",
                "refType": "jsonata"
            }
        },
        "outputs": 2,
        "output": "mimir.output",
        "host": {
            "type": "string",
            "value": "SECRETS.MIMIR_BASE_URL",
            "refType": "global"
        },
        "x": 610,
        "y": 520,
        "wires": [
            [
                "aad729927acbdfc6"
            ],
            [
                "29eb9c44a389b64c"
            ]
        ]
    },
    {
        "id": "2095c96067df70a4",
        "type": "openai-api-client",
        "z": "8fbe661c97151225",
        "name": "Rap the Rhymes",
        "selectedOperation": {
            "method": "post",
            "path": "/chat/completions",
            "summary": "Creates a completion for the chat message",
            "tag": "OpenAI",
            "operationId": "createChatCompletion"
        },
        "api": "api-0",
        "errorHandlingModeSelectedIndex": 1,
        "security": [
            {
                "id": "ApiKeyAuth",
                "type": "http",
                "description": "",
                "scheme": "bearer"
            }
        ],
        "requestContentTypeSelectedIndex": 0,
        "responseContentTypeSelectedIndex": 0,
        "parameters": [
            {
                "name": "body",
                "value": "{\n   \"model\": openai.model,\n   \"messages\": [\n       {\n           \"role\": \"system\",\n           \"content\": openai.systemPrompt\n    },\n       {\n           \"role\": \"user\",\n           \"content\": openai.userPrompt\n    }\n  ]\n}",
                "in": "body",
                "refType": "jsonata"
            }
        ],
        "uiFeatures": {
            "operations": {
                "advancedMode": true
            }
        },
        "credentialValues": {
            "username": {
                "value": "",
                "type": "string",
                "refType": "type"
            },
            "password": {
                "value": "",
                "type": "string",
                "refType": "type"
            },
            "value": {
                "value": "SECRETS.OPEN_AI_API_KEY",
                "type": "string",
                "refType": "global"
            }
        },
        "outputs": 2,
        "output": "openai.output",
        "host": {
            "type": "string",
            "value": "",
            "refType": "type"
        },
        "x": 180,
        "y": 520,
        "wires": [
            [
                "d638c9f3832a26e1"
            ],
            [
                "e1d94d444cc18f58"
            ]
        ]
    },
    {
        "id": "79fef2d9e512b8b7",
        "type": "qibb-secret-manager-sync",
        "z": "8fbe661c97151225",
        "name": "",
        "SYNC_PERIOD": "30min",
        "SYNC_ON_DEPLOY": true,
        "x": 140,
        "y": 60,
        "wires": []
    },
    {
        "id": "77b1d561353e8476",
        "type": "debug",
        "z": "8fbe661c97151225",
        "name": "debug 13",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "counter",
        "x": 820,
        "y": 1200,
        "wires": []
    }
]