I’m working with Claude’s API which is stateless and requires sending the full conversation history to the API (alternating “user” and “assistant” messages) like this:
messages=[
{"role": "user", "content": "Hello, Claude"},
{"role": "assistant", "content": "Hello!"},
{"role": "user", "content": "Can you describe LLMs to me?"}
]
I have created a “messages” variable that is an array. This variable will hold the prompts and responses and is what I pass into the API as the “messages” part in the above code.
The basic idea is I pass in a prompt to the API, get the response, and add() the response to the array variable so that it now contains the prompt + the response. Then add prompt #2 to the variable, and keep looping through until all prompts have been sent.
I’m having a hard time getting the data correct for this to work.
The first issue is Make telling me I don’t have proper JSON. I’m parsing the response from the HTTP module, and inserting it into a JSON string like so:
Which gives me this error:
OK, so then I decide to create JSON using that content like so:
Then I insert a parse JSON module after it which gives me this:
I then add that to my “messages” variable array, but you can see the structure is now an array within an array, rather than a collection in an array:
Which means, once I loop back through to get the next prompt, I now have an array with:
- a collection (prompt 1),
- an array (response 1), and
- a collection (prompt 2) as seen here:
This obviously then throws an error when trying to pass it into the API.
I tried using the toCollection() function on the response, which didn’t seem to work.
I’m a bit lost on what to do here.