How to force to use a specific tool with "gpt-4-1106-preview"

I want to force a specific tool when using the updated function calling that uses"tools":

            response = client.chat.completions.create(
                model="gpt-4-1106-preview",
                messages=messages,
                tools=tools,
                tool_choice="auto",
            )

whatever I wrote as “tool_choice” parameter, I always get an error.
So I simply want to know what sintax to use here:

tool_choice="auto"

to force a tool.

The sintax previusly used:

tool_choice={“name”: “generate_properties”}

gives an error.

Hi,

What is the actual error code you get? The syntax looks correct, but I’ve not checked.

The syntax is incorrect. A mandatory (at least telling AI it is mandatory) tool is an object in an object. (single element dictionary with a dictionary as the value)

tool_choice
string or object
Optional
Controls which (if any) function is called by the model. none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function. Specifying a particular function via

{"type: "function", "function": {"name": "my_function"}}

forces the model to call that function.

none is the default when no functions are present. auto is the default if functions are present.

For creating the right type of object instead of “auto” string:

object

Specifies a tool the model should use. Use to force the model to call a specific function.

type
string
Optional
The type of the tool. Currently, only function is supported.

function
object
Optional

name
string
Required
The name of the function to call.

1 Like

Thank you, with that sintax if worked:

{“type”: “function”, “function”: {“name”: “my_function”}}

2 Likes

It’s described here
image
and also here

1 Like