Where can I find the syntax of the function template/schema for Assistants?

I currently use functions in Assistants. However, to be able to use functions from libraries I wrote without making them incompatible with existing code (Python), I added a keyword parameter (key=default value) to all functions called by the Assistants in case they need to return text (instead of numeric values or dicts, etc.) whenever they are used within an Assistant. If the parameter is not defined in the function call, everything works as before. If the parameter is defined as “mode=‘chatgpt’”, the function returns text. Therefore, an Assistant must always include in the returned parameters, awaiting to receive the tool_output, a constant value “mode=‘chatgpt’”. I don’t know how to proceed.

to be short:

This is the function def i want to describe in a function template:

def get_moons_in_year(d, n: int, t: str, mode='code') -> List[Tuple[ephem.Date, str]]:

I need the Assistante returned :

get_moons_in_year("d":"2024-02-3","n":1,"t":"prossima","mode=chatgpt"})

the assistant instead returns always as following:

get_moons_in_year("d":"2024-02-23","n":1,"t":"prossima"})

Thank you in advance

I don’t know much python but i would create a separate “shim” function that only receives GPT calls, and inside it makes the call to get_moons_in_year and parses that output to the string you want to pass back.

Although, what you are asking for, I think you must mark the parameter as “required” in the spec. Under the function, you can provide an array of parameter names, which MUST be supplied. But, personally I think the “mode” approach is going to cause a lot of complexity and problems over time

Yes I could wrap the to-be-called function in many wsys. Unfortunately not all functions requires such “constant” parameters and I would not change the package funcs too much.
I am sure there Is a way to declare such a case in the schema. But I ignore which.

‘required’ keyword is what you want i think. So d, n, t, and mode would all be listed under required

or, you could make ‘mode’ an optional parameter on the python side, with a default value of ‘chatgpt’. So, if the assistant ever forgets to include it, it will default to ‘chatgpt’ anyways. And your puthon code will always pass some value. But this is a bad option, ‘required’ keyword in the openapi spec is the most direct solution

by the way it is a little incorrect for the mode to be named chatgpt, since chatgpt is the web frontend version. assistants are not chatgpt, i believe. they are API, even if they both use the same models. well, probably chatGPT is actually an assitant inside their servers, but they are particular about chatgpt being a specific product

I cannot use mode as parameter as it break the compatibility with other apps using those packages. As a workaround I added a keyword mode=“xxx” defaulting to “code” to assure backward compatibility., and I add hardcoded mode=“chatgpt” just when the functions are called from openai APIs.
This is not so elegant as I would like it to be (you know I’m a esthete … :smile: ).
Even more, Assistant never return me, as parameter, mode as it is a constant value I suppose and is ignored.

p.s. Yes, you right about “chatgpt”. It is a remembrance of older API code I used with completion chatgpt APIs…

It seems the way to force something to be chosen is with a string enum.

However, you are just going to make the function calling all that much more terrible with single letter names. A translator will improve the quality.

Imagine how much better it would be at writing the outputs if it was completing a parameter “today_date_YYYY-MM-DD” instead of “d”.

functions = [
{
    "name": "get_moons_in_year",
    "description": "This is the main function description",
    "parameters": {
        "type": "object",
        "properties": {
"today_date_yyyy-mm-dd": {"type": "string", "description": ""},
"n": {"type": "number", "description": ""},
"t": {"type": "string", "description": ""},
"mode": {"type": "string", "enum": ["chatgpt"], 
         "description": "always 'chatgpt'"},
        },
        "required": ["mode", ...]
    }
}
]

I accept your point! :slight_smile:
Help Assistant to help you!