Skip to content

Commit a669541

Browse files
committed
feat(api): add required tool_choice (openai#1382)
1 parent ffa8483 commit a669541

10 files changed

+97
-82
lines changed

src/openai/resources/beta/threads/runs/runs.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ def create(
187187
188188
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
189189
not call any tools and instead generates a message. `auto` is the default value
190-
and means the model can pick between generating a message or calling a tool.
191-
Specifying a particular tool like `{"type": "file_search"}` or
190+
and means the model can pick between generating a message or calling one or more
191+
tools. `required` means the model must call one or more tools before responding
192+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
192193
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
193194
call that tool.
194195
@@ -330,8 +331,9 @@ def create(
330331
331332
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
332333
not call any tools and instead generates a message. `auto` is the default value
333-
and means the model can pick between generating a message or calling a tool.
334-
Specifying a particular tool like `{"type": "file_search"}` or
334+
and means the model can pick between generating a message or calling one or more
335+
tools. `required` means the model must call one or more tools before responding
336+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
335337
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
336338
call that tool.
337339
@@ -473,8 +475,9 @@ def create(
473475
474476
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
475477
not call any tools and instead generates a message. `auto` is the default value
476-
and means the model can pick between generating a message or calling a tool.
477-
Specifying a particular tool like `{"type": "file_search"}` or
478+
and means the model can pick between generating a message or calling one or more
479+
tools. `required` means the model must call one or more tools before responding
480+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
478481
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
479482
call that tool.
480483
@@ -1716,8 +1719,9 @@ async def create(
17161719
17171720
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
17181721
not call any tools and instead generates a message. `auto` is the default value
1719-
and means the model can pick between generating a message or calling a tool.
1720-
Specifying a particular tool like `{"type": "file_search"}` or
1722+
and means the model can pick between generating a message or calling one or more
1723+
tools. `required` means the model must call one or more tools before responding
1724+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
17211725
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
17221726
call that tool.
17231727
@@ -1859,8 +1863,9 @@ async def create(
18591863
18601864
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
18611865
not call any tools and instead generates a message. `auto` is the default value
1862-
and means the model can pick between generating a message or calling a tool.
1863-
Specifying a particular tool like `{"type": "file_search"}` or
1866+
and means the model can pick between generating a message or calling one or more
1867+
tools. `required` means the model must call one or more tools before responding
1868+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
18641869
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
18651870
call that tool.
18661871
@@ -2002,8 +2007,9 @@ async def create(
20022007
20032008
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
20042009
not call any tools and instead generates a message. `auto` is the default value
2005-
and means the model can pick between generating a message or calling a tool.
2006-
Specifying a particular tool like `{"type": "file_search"}` or
2010+
and means the model can pick between generating a message or calling one or more
2011+
tools. `required` means the model must call one or more tools before responding
2012+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
20072013
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
20082014
call that tool.
20092015

src/openai/resources/beta/threads/threads.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ def create_and_run(
365365
366366
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
367367
not call any tools and instead generates a message. `auto` is the default value
368-
and means the model can pick between generating a message or calling a tool.
369-
Specifying a particular tool like `{"type": "file_search"}` or
368+
and means the model can pick between generating a message or calling one or more
369+
tools. `required` means the model must call one or more tools before responding
370+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
370371
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
371372
call that tool.
372373
@@ -507,8 +508,9 @@ def create_and_run(
507508
508509
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
509510
not call any tools and instead generates a message. `auto` is the default value
510-
and means the model can pick between generating a message or calling a tool.
511-
Specifying a particular tool like `{"type": "file_search"}` or
511+
and means the model can pick between generating a message or calling one or more
512+
tools. `required` means the model must call one or more tools before responding
513+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
512514
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
513515
call that tool.
514516
@@ -649,8 +651,9 @@ def create_and_run(
649651
650652
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
651653
not call any tools and instead generates a message. `auto` is the default value
652-
and means the model can pick between generating a message or calling a tool.
653-
Specifying a particular tool like `{"type": "file_search"}` or
654+
and means the model can pick between generating a message or calling one or more
655+
tools. `required` means the model must call one or more tools before responding
656+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
654657
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
655658
call that tool.
656659
@@ -1336,8 +1339,9 @@ async def create_and_run(
13361339
13371340
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
13381341
not call any tools and instead generates a message. `auto` is the default value
1339-
and means the model can pick between generating a message or calling a tool.
1340-
Specifying a particular tool like `{"type": "file_search"}` or
1342+
and means the model can pick between generating a message or calling one or more
1343+
tools. `required` means the model must call one or more tools before responding
1344+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
13411345
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
13421346
call that tool.
13431347
@@ -1478,8 +1482,9 @@ async def create_and_run(
14781482
14791483
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
14801484
not call any tools and instead generates a message. `auto` is the default value
1481-
and means the model can pick between generating a message or calling a tool.
1482-
Specifying a particular tool like `{"type": "file_search"}` or
1485+
and means the model can pick between generating a message or calling one or more
1486+
tools. `required` means the model must call one or more tools before responding
1487+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
14831488
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
14841489
call that tool.
14851490
@@ -1620,8 +1625,9 @@ async def create_and_run(
16201625
16211626
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
16221627
not call any tools and instead generates a message. `auto` is the default value
1623-
and means the model can pick between generating a message or calling a tool.
1624-
Specifying a particular tool like `{"type": "file_search"}` or
1628+
and means the model can pick between generating a message or calling one or more
1629+
tools. `required` means the model must call one or more tools before responding
1630+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
16251631
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
16261632
call that tool.
16271633

src/openai/resources/chat/completions.py

+42-42
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ def create(
171171
172172
We generally recommend altering this or `top_p` but not both.
173173
174-
tool_choice: Controls which (if any) function is called by the model. `none` means the model
175-
will not call a function and instead generates a message. `auto` means the model
176-
can pick between generating a message or calling a function. Specifying a
177-
particular function via
174+
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
175+
not call any tool and instead generates a message. `auto` means the model can
176+
pick between generating a message or calling one or more tools. `required` means
177+
the model must call one or more tools. Specifying a particular tool via
178178
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
179-
call that function.
179+
call that tool.
180180
181-
`none` is the default when no functions are present. `auto` is the default if
182-
functions are present.
181+
`none` is the default when no tools are present. `auto` is the default if tools
182+
are present.
183183
184184
tools: A list of tools the model may call. Currently, only functions are supported as a
185185
tool. Use this to provide a list of functions the model may generate JSON inputs
@@ -339,15 +339,15 @@ def create(
339339
340340
We generally recommend altering this or `top_p` but not both.
341341
342-
tool_choice: Controls which (if any) function is called by the model. `none` means the model
343-
will not call a function and instead generates a message. `auto` means the model
344-
can pick between generating a message or calling a function. Specifying a
345-
particular function via
342+
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
343+
not call any tool and instead generates a message. `auto` means the model can
344+
pick between generating a message or calling one or more tools. `required` means
345+
the model must call one or more tools. Specifying a particular tool via
346346
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
347-
call that function.
347+
call that tool.
348348
349-
`none` is the default when no functions are present. `auto` is the default if
350-
functions are present.
349+
`none` is the default when no tools are present. `auto` is the default if tools
350+
are present.
351351
352352
tools: A list of tools the model may call. Currently, only functions are supported as a
353353
tool. Use this to provide a list of functions the model may generate JSON inputs
@@ -507,15 +507,15 @@ def create(
507507
508508
We generally recommend altering this or `top_p` but not both.
509509
510-
tool_choice: Controls which (if any) function is called by the model. `none` means the model
511-
will not call a function and instead generates a message. `auto` means the model
512-
can pick between generating a message or calling a function. Specifying a
513-
particular function via
510+
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
511+
not call any tool and instead generates a message. `auto` means the model can
512+
pick between generating a message or calling one or more tools. `required` means
513+
the model must call one or more tools. Specifying a particular tool via
514514
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
515-
call that function.
515+
call that tool.
516516
517-
`none` is the default when no functions are present. `auto` is the default if
518-
functions are present.
517+
`none` is the default when no tools are present. `auto` is the default if tools
518+
are present.
519519
520520
tools: A list of tools the model may call. Currently, only functions are supported as a
521521
tool. Use this to provide a list of functions the model may generate JSON inputs
@@ -751,15 +751,15 @@ async def create(
751751
752752
We generally recommend altering this or `top_p` but not both.
753753
754-
tool_choice: Controls which (if any) function is called by the model. `none` means the model
755-
will not call a function and instead generates a message. `auto` means the model
756-
can pick between generating a message or calling a function. Specifying a
757-
particular function via
754+
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
755+
not call any tool and instead generates a message. `auto` means the model can
756+
pick between generating a message or calling one or more tools. `required` means
757+
the model must call one or more tools. Specifying a particular tool via
758758
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
759-
call that function.
759+
call that tool.
760760
761-
`none` is the default when no functions are present. `auto` is the default if
762-
functions are present.
761+
`none` is the default when no tools are present. `auto` is the default if tools
762+
are present.
763763
764764
tools: A list of tools the model may call. Currently, only functions are supported as a
765765
tool. Use this to provide a list of functions the model may generate JSON inputs
@@ -919,15 +919,15 @@ async def create(
919919
920920
We generally recommend altering this or `top_p` but not both.
921921
922-
tool_choice: Controls which (if any) function is called by the model. `none` means the model
923-
will not call a function and instead generates a message. `auto` means the model
924-
can pick between generating a message or calling a function. Specifying a
925-
particular function via
922+
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
923+
not call any tool and instead generates a message. `auto` means the model can
924+
pick between generating a message or calling one or more tools. `required` means
925+
the model must call one or more tools. Specifying a particular tool via
926926
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
927-
call that function.
927+
call that tool.
928928
929-
`none` is the default when no functions are present. `auto` is the default if
930-
functions are present.
929+
`none` is the default when no tools are present. `auto` is the default if tools
930+
are present.
931931
932932
tools: A list of tools the model may call. Currently, only functions are supported as a
933933
tool. Use this to provide a list of functions the model may generate JSON inputs
@@ -1087,15 +1087,15 @@ async def create(
10871087
10881088
We generally recommend altering this or `top_p` but not both.
10891089
1090-
tool_choice: Controls which (if any) function is called by the model. `none` means the model
1091-
will not call a function and instead generates a message. `auto` means the model
1092-
can pick between generating a message or calling a function. Specifying a
1093-
particular function via
1090+
tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
1091+
not call any tool and instead generates a message. `auto` means the model can
1092+
pick between generating a message or calling one or more tools. `required` means
1093+
the model must call one or more tools. Specifying a particular tool via
10941094
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
1095-
call that function.
1095+
call that tool.
10961096
1097-
`none` is the default when no functions are present. `auto` is the default if
1098-
functions are present.
1097+
`none` is the default when no tools are present. `auto` is the default if tools
1098+
are present.
10991099
11001100
tools: A list of tools the model may call. Currently, only functions are supported as a
11011101
tool. Use this to provide a list of functions the model may generate JSON inputs

src/openai/types/beta/assistant_tool_choice_option.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
__all__ = ["AssistantToolChoiceOption"]
99

10-
AssistantToolChoiceOption = Union[Literal["none", "auto"], AssistantToolChoice]
10+
AssistantToolChoiceOption = Union[Literal["none", "auto", "required"], AssistantToolChoice]

src/openai/types/beta/assistant_tool_choice_option_param.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
__all__ = ["AssistantToolChoiceOptionParam"]
1111

12-
AssistantToolChoiceOptionParam = Union[Literal["none", "auto"], AssistantToolChoiceParam]
12+
AssistantToolChoiceOptionParam = Union[Literal["none", "auto", "required"], AssistantToolChoiceParam]

src/openai/types/beta/thread_create_and_run_params.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ class ThreadCreateAndRunParamsBase(TypedDict, total=False):
135135
"""
136136
Controls which (if any) tool is called by the model. `none` means the model will
137137
not call any tools and instead generates a message. `auto` is the default value
138-
and means the model can pick between generating a message or calling a tool.
139-
Specifying a particular tool like `{"type": "file_search"}` or
138+
and means the model can pick between generating a message or calling one or more
139+
tools. `required` means the model must call one or more tools before responding
140+
to the user. Specifying a particular tool like `{"type": "file_search"}` or
140141
`{"type": "function", "function": {"name": "my_function"}}` forces the model to
141142
call that tool.
142143
"""

0 commit comments

Comments
 (0)