Making dynamic function calling work with the new Assistant API

Hey, I’ve been trying out the new Assistant API to determine whether I should migrate my program to use it instead of the Chat Completions API.

However, I’m having a really hard time figuring out how to dynamically add, remove, and change the JSON functions the model has access to, like I’ve been doing (with good results) using the normal Chat API.

What I mean by “dynamic function calling”
Each time a function call is made, I change the functions that will be used for the next completion based on the current state of the system. I also switch between different fine-tuned models when certain function calls have been made. Before one message directed at the user is written, the model will produce between 5-10 function calls, most of which involve editing the function’s parameters and or switching models.

What I’m struggling with
How would I go about changing the functions in the same way with the Assistant API, considering a “run” would last multiple function calls and only finish once the model provides an answer that is not a function call? Because, as I understand it, you are not able to change the parameters of the assistant or the thread while a run is still active. I know you can cancel runs and use the same thread when starting new ones. But canceling and starting a new one between every function call generated by the model would negate the whole purpose of using runs in the first place.
I also haven’t been able to figure out how to “force” the model to use a function like you could by using the function_call parameter in a chat completion. Is that not possible using the Assistant API?

I’ve read through the new documentation and API reference, but I’m still wildly unsure if I’m being stupid or missing something really obvious.

Sorry if the post got a little long; I hope it made some sense! I’ve been sitting with this for way too long now, going a little bit crazy, so I would appreciate any thoughts or input :grinning:


hello dear friend im not sure if it will help but ive had good luck with my specific uses in my repo on github
You can search github for OPENAI_Assistant_Python_Dynamic_function_call_on_demand
Not quite sure about your use case tho, We will see!


Hahah no need to advertise! Starred that repo and have been following updates since like day 2 it was posted :grinning:

@kodiea Can you please link me to this notebook or repo?


@Reversehobo Can you link me that repo? I can’t find it. Thanks!

Couldn’t find it myself first but simply googling “OPENAI_Assistant_Python_Dynamic_function_call_on_demand” it was the first result. As a programmer you should look in to that.

I was coming up with different results. Thank you.

No worries, sorry for being a bit smug, bad day.