Best answer

How to parse GET response in Code step with Python

  • 30 January 2024
  • 3 replies
  • 58 views

Userlevel 1

Hi,

I have a GET Webhook that retrieves all the messages from a conversation previously created using an LLM app (CustomGPT)

The data received as the following structure:

data

    Conversation

        Conv ID

        Conv Created at

        …..

    Messages

       Current page

       data

          1 

              xxxx

              AI Response

           2

              yyyyy

              AI response

I want to retrieve the AI response of the last message in the conversation.

I have tried to use a Code step with Python to process the output of the GET.

The output of the GET has a field that contains all the responses in the following format:

responses_list = AI_response1, AI_response 2, AI_response3, etc.

I have tried to split it with:

output = input_data["responses_list"].split(",")

Since each response may contain commas, I cannot isolate the responses but only phrases between commas.

I have tried to get a JSON key output by selecting the option in the GET step, but I was not able to find a way to access that JSON output from the Code step.

Any suggestion on how to address this issue?

Thanks!

icon

Best answer by Troy Tessalone 30 January 2024, 02:12

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 1

Sorry, I want to access the first response in the list, i.e. reposnse1. The GET request order the messages so that the first messages is the latest

Userlevel 7
Badge +14

Hi @VittorioP 

Looks like the data from the GET is returned as an array.

One option is to use the Looping (Create Loop from Line Items) app followed by a Filter to only continue if Loop Iteration = 1.

 

Another options would be to use Formatter > Utilities > Line Items to Text, followed by Formatter > Text > Split (return as separate fields).

Userlevel 1

@Troy Tessalone 

thank you for your answer!

I ended up using Formatter > Utilities > Pick from List > Choose First.

It works in my case in one step.