'This' not working with function calling

Recently, I have ran into an annoying behavior: ‘this’ is not working with function calling.

‘this’ is used in Object Oriented Programming for giving context to a function. Thus, we can call one function, but use several that are inside the same object, also, variables.

For instance, I have a service in Angular. This service has a general model, and more especific models. The more specific model is just calling the general model, but adding a parametrization. Thus, it makes something like this.general_model ("model 1"). Whereas the function calling will call the specific model instead.

I have tried, but when call the function myself, it works; when I can do it with functioin calling, it complains the this.function and this.variable is missing. Thougth a lot about it. The only explanation: functon calling has a static version of the functions, without any context.

First, I thought, it was a JavaScript thing after doing the function mapping.
But, I ran into this on the documentation:

“Under the hood, functions are injected into the system message in a syntax the model has been trained on.” Source

So, it means the function is actually passed as a text, not as a object reference.
They also say:

“This means functions count against the model’s context limit and are billed as input tokens. If running into context limits, we suggest limiting the number of functions or the length of documentation you provide for function parameters.”

Any thoughts from OOP programmers? :thinking:

Oi Jorge

Could you elaborate your question?

As I think somebody commented on your other topic, function calling just converts user’s input to a json that is used as a schema to run functions. If you wanted something more complex (like passing specific types, you’d probably need to do function calling yourself, or maybe have a function that is called by OpenAI and then does the needed translation from text to the required types.

1 Like

The questions come from the same project I am running, but they are different. The previous, which the person did not answer, I have solved with ifs. This one is about how function calling handles the function. It seems it makes a static copy of the function, and call it. That is, it loses any context it has. I will see what I can do. :ok_hand::two_hearts:

1 Like

The AI has been tuned to generate json. Within that json is AI-written language. The AI will use the parameter name and the parameter description to fill the json key/value pair with data.

The AI is already calling a function. Getting it to call another function within part of the output of its function would really be a test. You will likely need to write your own code to interface with different APIs.

Expect that all you are going to get out of the function-calling AI will be json as you dictate in your specification, and you are going to have an easier time. Make the json be something your own code can reinterpret to write what you ultimately desire.

Some imagination:

"function": {
  "name": "angular",
  "arguments": "{
    "model_name": "general_model",
    "model_parameter_count": 1,
    "model_parameter_array": ["model 1"],
    "model_function_query": "drop tables",

The AI must understand and also have the capacity to understand. Having an AI interact with stateful objects is just going to be out of reach.

1 Like

Thanks for all the efford in answering my questions! :ok_hand::two_hearts::heart:

It is not an API, with APIs, it works. It is an object oriented programming stuff.

It means that if you are coding using OOP, you will need to rewrite your functions to be self-contained, no usage of ‘this’. If you are planning to code using OOP, it does not work with function calling. :unamused:

Your function has to be an isolated box, with no context. It makes sense since their API treats the function as text. Even the JSON has to stringfied.

I could easily let it call the models directly, like, model 1 directly instead of generic model, passing the models as parameter. I want to make sure it knows what each model does, instead of letting it guess. So, when it call say model_1, it supposes to call generic model, which uses this to parametrize using the generic model.

JSON → interface for programming an application → destination code