How do I extract values from the output of the perplexity AI module that runs in an iterator?

I need to extract the outputs of the perplexity AI module that runs in an iterator, and write it to a Google sheet. Here is the blueprint of the scenario.
blueprint (1).json (69.1 KB)

the scenario looks like this:

The output bundle from the Array aggregator (operation 1) is given below:

[
    {
        "array": [
            {
                "choices": [
                    {
                        "index": 0,
                        "finish_reason": "stop",
                        "message": {
                            "role": "assistant",
                            "content": "The topic \"Ideas for SaaS products\" involves identifying and developing software as a service (SaaS) applications that solve specific problems for users and businesses. Successful SaaS products address real pain points and are designed to be user-friendly, eliminating the need for installation, configuration, and updates. Historical context shows that SaaS solutions have become increasingly popular due to their convenience and scalability. Current significance lies in the growing demand for digital solutions, making it crucial for entrepreneurs to find innovative ideas that meet these needs. Market research and validation of ideas through proof of concept and MVP development are essential steps in creating a successful SaaS product."
                        },
                        "delta": {
                            "role": "assistant",
                            "content": ""
                        }
                    }
                ]
            }
        ],
        "__IMTAGGLENGTH__": 1
    }
]

There are 3 operations like this (running in the iterator).

The input bundle for the google sheet module (after the array aggregator), operation 1:

[
    {
        "from": "drive",
        "mode": "select",
        "values": {},
        "sheetId": "research-fields-output",
        "rowNumber": 15,
        "spreadsheetId": "/1bFSMECDa0lAB57iGZ2Cgj8bSsju2Ctu9/1yXUBbmZd7tZP2Z070XNXhfWt2jWcCkW7/1vyInpt-mGnnjKn6pjHiX50IoojSADbWjZ_zilbBKpMA",
        "includesHeaders": true,
        "valueInputOption": "USER_ENTERED"
    }
]

these are the values that i am adding, inside the mapping for google sheets (update a row) module.

I also tried this variation -
Column D: {{24.Array[0].choices[0].message.content}}
Column E: {{24.Array[1].choices[0].message.content}}
Column F: {{24.Array[2].choices[0].message.content}}

These outputs are not getting written to the Google sheet.

Please help! I have read through documentation provided in different threads but can’t seem to understand how to fix this.

1 Like

See the difference between the corrected version in the first field, and how you were doing it in the second field?

Screenshot_2024-08-09_150836

Make sure this array has a solid background or you are doing it incorrectly.

Hope this helps! Let me know if there are any further questions or issues.

— @samliew

I tried doing this - but the google sheets output is still showing blank (for the first values) and showing “,2”, “,3” for the other 2 cells.

Your array Aggregator’s “Source Module” should be set to the Iterator module, because that is where the multiple operations are being output from.

Only then you can do this

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 217,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "[\n    {\n        \"array\": [\n            {\n                \"choices\": [\n                    {\n                        \"index\": 0,\n                        \"finish_reason\": \"stop\",\n                        \"message\": {\n                            \"role\": \"assistant\",\n                            \"content\": \"Item 1\"\n                        },\n                        \"delta\": {\n                            \"role\": \"assistant\",\n                            \"content\": \"\"\n                        }\n                    }\n                ]\n            },\n            {\n                \"choices\": [\n                    {\n                        \"index\": 0,\n                        \"finish_reason\": \"stop\",\n                        \"message\": {\n                            \"role\": \"assistant\",\n                            \"content\": \"Item 2\"\n                        },\n                        \"delta\": {\n                            \"role\": \"assistant\",\n                            \"content\": \"\"\n                        }\n                    }\n                ]\n            },\n            {\n                \"choices\": [\n                    {\n                        \"index\": 0,\n                        \"finish_reason\": \"stop\",\n                        \"message\": {\n                            \"role\": \"assistant\",\n                            \"content\": \"Item 3\"\n                        },\n                        \"delta\": {\n                            \"role\": \"assistant\",\n                            \"content\": \"\"\n                        }\n                    }\n                ]\n            }\n        ],\n        \"__IMTAGGLENGTH__\": 1\n    }\n]"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3020,
                            "y": -4278,
                            "name": "Array Aggregator"
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 218,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "topic_overview",
                                "value": "{{get(map(217.array; \"choices.1.message.content\"); 1)}}"
                            },
                            {
                                "name": "relevance_to_target_audience",
                                "value": "{{get(map(217.array; \"choices.1.message.content\"); 2)}}"
                            },
                            {
                                "name": "third_item",
                                "value": "{{get(map(217.array; \"choices.1.message.content\"); 3)}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3264,
                            "y": -4278
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null,
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "topic_overview",
                                "label": "topic_overview",
                                "type": "any"
                            },
                            {
                                "name": "relevance_to_target_audience",
                                "label": "relevance_to_target_audience",
                                "type": "any"
                            },
                            {
                                "name": "third_item",
                                "label": "third_item",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

Hope this helps! Let me know if there are any further questions or issues.

— @samliew