GPT4 with Tools. How to properly chain with dependencies?

Hello All - I am hoping someone more experienced can help me with structuring my code/thought. I have used the completion API and it all works fine. I am trying to graduate to next level where I would be deploying lot of tools/functions that would need to be “chained”. Assuming I would end up having lot of these functions/tools, I am trying to see how to use openai effectively.

If there is dependency between these functions (so output of one is an input for another), would openai be able to figure out the order ? Apologies if I am asking a basic question. Just trying to learn. I went through the How_to_call_functions_with_chat_models.ipynb cookbook (which had to be fixed with some formatting issues atleasr for me), I couldn’t tell how to organize the tools functions when there is a dependency. Thanks for pointers. Even better, if someone has any pointers to “chaining” using openai API, I’d appreciate it.

Hi! Welcome to the forums!

If you give the model methods it can call and tell it about the parameters, it should be able to decide in what order it should call them (as long as it’s not too complicated).

You can do the same thing with the native functions, but they’re a waste of tokens in most cases IMO (unless you’re working with assistants).

1 Like

I wrote a Python script to chain together all the models so if you ask to generate an image it gets sent to DALL-E otherwise the base model is GPT-3.5 unless you specify GPT-4.

Thank you so much. This is an interesting approach (I think I understand it roughly, need to explore how it would work when you have lot of agents, but the code is not embedded in the system command).

When you say chain, did you use functions with descriptions to separate out GPT3.5 vs GPT4 ?

You need to specify in the system prompt how you want the tools to be chained together. Here is an example using Assistants API but it can be similarly applied in Chat completions API:

System Prompt:

You are a helpful personal assistant.
You have the following tools you can invoke depending on user request.
- generateRandomInteger, when the user wants to generate a random number.
- showEvenNumberMessage, when generateRandomInteger outputs even number.
- showOddNumberMessage, when the generateRandomInteger outputs odd number.
Depending on the output of generateRandomInteger, call either showEvenNumberMessage or showOddNumberMessage.

Here is sample conversation: