Function calling with a list of lists

I was trying to use function-calling on rather large functions, so as a way of using less tokens I was passing my functions in a list of lists through a for loop where if the function call is attained then you call the function, but the model then tends to pick the very first function instead of the correct one when they may be similar, how can that be avoided

I think you have a misunderstanding.

The functions parameter of openai modules (or the function array of the request if constructing your own bytes to post) must include all functions you want the AI to be aware of for that conversation turn. The AI then picks which is useful for the user’s query.

api_params = {
"model": model,
"max_tokens": max_tokens,
"temperature": temperature,
"messages": all_messages
}
if functions_enabled:
    api_params["functions"] = all_functions
    api_params["function_call"] = "auto"

There’s only a few scenarios for “creative disabling” - like if you have a specific workflow.

One concept: you put the AI into “appointment booking” mode with all the appointment functions included only after the first time AI calls a single “appointments_enable” function.

There is not much compacting or compression you can do on the function data to save tokens. The format the AI actually receives is quite optimized by the API.

yeah but if it does not find the function matching the users query should it not break? otherwise it could be used with chat completion to figure out the best function and then have that function called maybe, I am trying to optimize the token usage for my use case which is currently at 2700

I can’t discern what you are attempting to do, but without specific system instruction telling the AI it is a data processor and that user input is only the data to be processed, then yes, it will like to chat.

The functions will be selected as to what best fulfills the need. If you have a static system prompt, then it likely does the same processing and function calling all the time on the input data. If you have a chatbot taking user input language, it will be using the best function to fulfill the user request.


Let’s say I want to: “Make a new post to community.openai.com discourse forum.
The category is API, the topic is Using OpenAI API, and you write contents.”

Normally it would say “I can’t access the internet”.

However, I give it a function that lets it go wild on the internet. It makes a barely-plausible function call…or maybe it has plans and could continue making requests after it authenticates somehow, and actually do it:

    "role": "assistant",
    "content": null,
    "function_call": {
      "name": "access_internet",
      "arguments": "{\n  \"URL\": \"https://community.openai.com/posts.json?api_key=YOUR_API_KEY\"\n}"
    }

Not entirely sure what the goal is, but if i think you mean what i think you mean… then ask the AI to write the script in parts.