I am currently working with the GPT API and have a specific requirement. I would like the bot to be able to recognize multiple functions in a single prompt and then execute each function call individually in a new API call. I use function calls.
For example, if I send a prompt like “Play me song xyz and then create me a word file about xyz”, I want the bot to recognize both functions and then execute them in two separate API calls.
However, I don’t want to create a function that executes multiple functions. I want that I can combine my functions as I want no matter what order.
I look forward to your feedback and thank you in advance for your assistance.
What you describe is the natural iterative process of the function-enabled AI.
You could say “find a cute cat picture from my instagram and post to my twitter”, and if it had functions where it could perform those tasks, it would use their description to figure out what to do step by step. The only thing the software must do is keep a “conversation history” that continues with the past chat and user question along with a function role return for the results of each call.
The correct way to add a function return to the chat history, below the question most recently asked, is with the “function” role message, requiring a “name” parameter with the function name that is returning the data.
One must keep a consecutive chat history of all functions the AI has called, at least until the AI finally answers the user.
We are not given any guidance, but I would put a pair of assistant/function roles in history for each return, where the assistant is written like <function_name>(<function_call_json>). That way AI also can see what it tried and won’t repeat the same mistakes.
This example from OpenAI documentation shows putting the whole API response “message” in instead of simulating the language the AI actually produced:
messages=[
{"role": "user", "content": "What is the weather like in boston?"},
message,
{
"role": "function",
"name": function_name,
"content": function_response,
},
],
I answered almost exactly this question just a few days ago.
Is this a school assignment or something?
No, wait … I answered it for you.
The answer is still the same. ChatGPT can only call one function at a time.
If you look at the API, there is literally no way it could call more than one function in a single invocation. There’s no space to return them.
In the previous answer, I described exactly how you could use chain of thought prompting to implement exactly what you’re suggesting.
Thank you this has helped me a lot. As you can see below I created a short test function so you know how the others look like. Normally I have multiple functions but to show you that there are strange results and reactions from the bot when I trigger multiple functions. The get_dynamic_reaction reacts on the functions what was executed. if i say open me word and turn on my light then it executes it but the reaction seems to be weird because the bot interprets it like wrong… What do you suggest to make it clearer?