How to correctly create a function description

I have this AI bot helping the user to set a new habit.
As a first question it usually asks what is the habit the user wants to set.
I want then get this input and store the new habit description in my db using function calling but the function is not called when I want.

As example with this easy fn description:

{
            name: "habitDefined",
            description: "New habit has been defined by the user",
            parameters: {
                type: "object",
                properties: {
                    habit: {
                        type: "string",
                        description: "Habit that the user wants to set",
                    },
                },
                required: ["habit"],
            },
        }

I had this chat:

AI: Hello! How can I assist you today? Are you looking to set a new habit?
USER: I want to start running as a new habit
// Here I wanted the function to be called but was not
....
USER: what is my new habit?
// Here instead the function has been called

How should I better define the function name and description to be called after the user describes it instead of when the user asks for it?

Hi. Perhaps “behavior” is the word you want to use. Habit is what humans learn by repetition.

It is indeed the quality of the description and the property names that tell the AI when a tool function is going to be useful. The description text can be multi-line when you use \n linefeeds within the string.

The AI generally doesn’t ask automatically. The first input is from the user, and then the AI decides if that user input is best served by a tool call first, such as a tool to gather new knowledge.

Imagine your tool like DALL-E tool that is used by AI within ChatGPT. The user asks for an image, and the AI knows the best tool to use instead of responding to the user. Follow that pattern, where the user requests their task, and the function emits what is needed to take the action and return a message or data.

I just compiled a playground preset for you. It is 2000+ tokens of system prompt teaching GPT-4 how to write functions (and sending them as “tools” in an API call). You can add your user request message stating what it is you want your function to do, what parameters your code needs, and the writing of the function will be taken care of by AI, a real time-saver:

https://platform.openai.com/playground/chat?models=gpt-4&preset=preset-T1lsiyLIcoXZoE1UEeeUPUAO

1 Like