I’m using the new function calling api to create an array of “layers” (think pages in a storybook) that each have a different idea and random metadata. It works flawlessly on the first try producing amazing results of layers - “create __ layers of text about ____” , but I’m unable to send it back in to edit the array. “Edit the second layer to _____”. For this made-up example, I send the original function results in back as a function type, followed by a prompt to edit the second layer, but it replaces the entire layers array with the new layer. Any advice how to edit an array created with function calling?
You don’t tell enough about the function and its parameters for me to really go on, but I can give ideas of typical use.
You should construct the second call to be including the same function AND the function role message AND the same user input. The AI should be able to then still understand the purpose of that function AND see in chat history it was asked a question that the function could answer AND match up the function role message being returned with the function name and the type of return it should be producing.
This would typically allow it to iterate, like trying other functions for a better answer. The same function again is a bit unusual.
A wild stab at what might work for you:
You could phrase your input like “I’d like you to process this text with create_layers. Then after you receive the response back, I’d like you to call the create_layers function again, processing the prior output again in this different way.”
You’d need to figure out the right chat history to let it know whether it is the second AI, or third AI that gets the final result and displays to user. A loop could form.
Thank you for the helpful suggestion - I ended up ultimately solving this by “massaging” the messages array to show the latest version of the function containing the current data, immediately followed by a made up message from assistant:
{ role: 'assistant', content: 'There you go, Ive created it for you. Let me know how you would like to edit it.' }
immediately followed by the users latest prompt. Hope this helps someone.