Class Tool
-
- All Implemented Interfaces:
public final class ToolA tool that can be used to generate a response.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceTool.VisitorAn interface that defines how to map each variant of Tool to a value of type T.
public final classTool.McpGive the model access to additional tools via remote Model Context Protocol (MCP) servers. Learn more about MCP.
public final classTool.CodeInterpreterA tool that runs Python code to help generate a response to a prompt.
public final classTool.ImageGenerationA tool that generates images using the GPT image models.
-
Method Summary
Modifier and Type Method Description final Optional<FunctionTool>function()Defines a function in your own code the model can choose to call. final Optional<FileSearchTool>fileSearch()A tool that searches for relevant content from uploaded files. final Optional<ComputerTool>computer()A tool that controls a virtual computer. final Optional<ComputerUsePreviewTool>computerUsePreview()A tool that controls a virtual computer. final Optional<WebSearchTool>webSearch()Search the Internet for sources related to the prompt. final Optional<Tool.Mcp>mcp()Give the model access to additional tools via remote Model Context Protocol (MCP) servers. final Optional<Tool.CodeInterpreter>codeInterpreter()A tool that runs Python code to help generate a response to a prompt. final Optional<Tool.ImageGeneration>imageGeneration()A tool that generates images using the GPT image models. final Optional<JsonValue>localShell()A tool that allows the model to execute shell commands in a local environment. final Optional<FunctionShellTool>shell()A tool that allows the model to execute shell commands. final Optional<CustomTool>custom()A custom tool that processes input using a specified format. final Optional<NamespaceTool>namespace()Groups function/custom tools under a shared namespace. final Optional<ToolSearchTool>search()Hosted or BYOT tool search configuration for deferred tools. final Optional<WebSearchPreviewTool>webSearchPreview()This tool searches the web for relevant results to use in a response. final Optional<ApplyPatchTool>applyPatch()Allows the assistant to create, delete, or update files using unified diffs. final BooleanisFunction()final BooleanisFileSearch()final BooleanisComputer()final BooleanisComputerUsePreview()final BooleanisWebSearch()final BooleanisMcp()final BooleanisCodeInterpreter()final BooleanisImageGeneration()final BooleanisLocalShell()final BooleanisShell()final BooleanisCustom()final BooleanisNamespace()final BooleanisSearch()final BooleanisWebSearchPreview()final BooleanisApplyPatch()final FunctionToolasFunction()Defines a function in your own code the model can choose to call. final FileSearchToolasFileSearch()A tool that searches for relevant content from uploaded files. final ComputerToolasComputer()A tool that controls a virtual computer. final ComputerUsePreviewToolasComputerUsePreview()A tool that controls a virtual computer. final WebSearchToolasWebSearch()Search the Internet for sources related to the prompt. final Tool.McpasMcp()Give the model access to additional tools via remote Model Context Protocol (MCP) servers. final Tool.CodeInterpreterasCodeInterpreter()A tool that runs Python code to help generate a response to a prompt. final Tool.ImageGenerationasImageGeneration()A tool that generates images using the GPT image models. final JsonValueasLocalShell()A tool that allows the model to execute shell commands in a local environment. final FunctionShellToolasShell()A tool that allows the model to execute shell commands. final CustomToolasCustom()A custom tool that processes input using a specified format. final NamespaceToolasNamespace()Groups function/custom tools under a shared namespace. final ToolSearchToolasSearch()Hosted or BYOT tool search configuration for deferred tools. final WebSearchPreviewToolasWebSearchPreview()This tool searches the web for relevant results to use in a response. final ApplyPatchToolasApplyPatch()Allows the assistant to create, delete, or update files using unified diffs. final Optional<JsonValue>_json()final <T extends Any> Taccept(Tool.Visitor<T> visitor)Maps this instance's current variant to a value of type T using the given visitor. final Toolvalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static ToolofFunction(FunctionTool function)Defines a function in your own code the model can choose to call. final static ToolofFileSearch(FileSearchTool fileSearch)A tool that searches for relevant content from uploaded files. final static ToolofComputer(ComputerTool computer)A tool that controls a virtual computer. final static ToolofComputerUsePreview(ComputerUsePreviewTool computerUsePreview)A tool that controls a virtual computer. final static ToolofWebSearch(WebSearchTool webSearch)Search the Internet for sources related to the prompt. final static ToolofMcp(Tool.Mcp mcp)Give the model access to additional tools via remote Model Context Protocol (MCP) servers. final static ToolofCodeInterpreter(Tool.CodeInterpreter codeInterpreter)A tool that runs Python code to help generate a response to a prompt. final static ToolofImageGeneration(Tool.ImageGeneration imageGeneration)A tool that generates images using the GPT image models. final static ToolofLocalShell()A tool that allows the model to execute shell commands in a local environment. final static ToolofShell(FunctionShellTool shell)A tool that allows the model to execute shell commands. final static ToolofCustom(CustomTool custom)A custom tool that processes input using a specified format. final static ToolofNamespace(NamespaceTool namespace)Groups function/custom tools under a shared namespace. final static ToolofSearch(ToolSearchTool search)Hosted or BYOT tool search configuration for deferred tools. final static ToolofWebSearchPreview(WebSearchPreviewTool webSearchPreview)This tool searches the web for relevant results to use in a response. final static ToolofApplyPatch(ApplyPatchTool applyPatch)Allows the assistant to create, delete, or update files using unified diffs. -
-
Method Detail
-
function
final Optional<FunctionTool> function()
Defines a function in your own code the model can choose to call. Learn more about function calling.
-
fileSearch
final Optional<FileSearchTool> fileSearch()
A tool that searches for relevant content from uploaded files. Learn more about the file search tool.
-
computer
final Optional<ComputerTool> computer()
A tool that controls a virtual computer. Learn more about the computer tool.
-
computerUsePreview
final Optional<ComputerUsePreviewTool> computerUsePreview()
A tool that controls a virtual computer. Learn more about the computer tool.
-
webSearch
final Optional<WebSearchTool> webSearch()
Search the Internet for sources related to the prompt. Learn more about the web search tool.
-
mcp
final Optional<Tool.Mcp> mcp()
Give the model access to additional tools via remote Model Context Protocol (MCP) servers. Learn more about MCP.
-
codeInterpreter
final Optional<Tool.CodeInterpreter> codeInterpreter()
A tool that runs Python code to help generate a response to a prompt.
-
imageGeneration
final Optional<Tool.ImageGeneration> imageGeneration()
A tool that generates images using the GPT image models.
-
localShell
final Optional<JsonValue> localShell()
A tool that allows the model to execute shell commands in a local environment.
-
shell
final Optional<FunctionShellTool> shell()
A tool that allows the model to execute shell commands.
-
custom
final Optional<CustomTool> custom()
A custom tool that processes input using a specified format. Learn more about custom tools
-
namespace
final Optional<NamespaceTool> namespace()
Groups function/custom tools under a shared namespace.
-
search
final Optional<ToolSearchTool> search()
Hosted or BYOT tool search configuration for deferred tools.
-
webSearchPreview
final Optional<WebSearchPreviewTool> webSearchPreview()
This tool searches the web for relevant results to use in a response. Learn more about the web search tool.
-
applyPatch
final Optional<ApplyPatchTool> applyPatch()
Allows the assistant to create, delete, or update files using unified diffs.
-
isFunction
final Boolean isFunction()
-
isFileSearch
final Boolean isFileSearch()
-
isComputer
final Boolean isComputer()
-
isComputerUsePreview
final Boolean isComputerUsePreview()
-
isWebSearch
final Boolean isWebSearch()
-
isCodeInterpreter
final Boolean isCodeInterpreter()
-
isImageGeneration
final Boolean isImageGeneration()
-
isLocalShell
final Boolean isLocalShell()
-
isNamespace
final Boolean isNamespace()
-
isWebSearchPreview
final Boolean isWebSearchPreview()
-
isApplyPatch
final Boolean isApplyPatch()
-
asFunction
final FunctionTool asFunction()
Defines a function in your own code the model can choose to call. Learn more about function calling.
-
asFileSearch
final FileSearchTool asFileSearch()
A tool that searches for relevant content from uploaded files. Learn more about the file search tool.
-
asComputer
final ComputerTool asComputer()
A tool that controls a virtual computer. Learn more about the computer tool.
-
asComputerUsePreview
final ComputerUsePreviewTool asComputerUsePreview()
A tool that controls a virtual computer. Learn more about the computer tool.
-
asWebSearch
final WebSearchTool asWebSearch()
Search the Internet for sources related to the prompt. Learn more about the web search tool.
-
asMcp
final Tool.Mcp asMcp()
Give the model access to additional tools via remote Model Context Protocol (MCP) servers. Learn more about MCP.
-
asCodeInterpreter
final Tool.CodeInterpreter asCodeInterpreter()
A tool that runs Python code to help generate a response to a prompt.
-
asImageGeneration
final Tool.ImageGeneration asImageGeneration()
A tool that generates images using the GPT image models.
-
asLocalShell
final JsonValue asLocalShell()
A tool that allows the model to execute shell commands in a local environment.
-
asShell
final FunctionShellTool asShell()
A tool that allows the model to execute shell commands.
-
asCustom
final CustomTool asCustom()
A custom tool that processes input using a specified format. Learn more about custom tools
-
asNamespace
final NamespaceTool asNamespace()
Groups function/custom tools under a shared namespace.
-
asSearch
final ToolSearchTool asSearch()
Hosted or BYOT tool search configuration for deferred tools.
-
asWebSearchPreview
final WebSearchPreviewTool asWebSearchPreview()
This tool searches the web for relevant results to use in a response. Learn more about the web search tool.
-
asApplyPatch
final ApplyPatchTool asApplyPatch()
Allows the assistant to create, delete, or update files using unified diffs.
-
accept
final <T extends Any> T accept(Tool.Visitor<T> visitor)
Maps this instance's current variant to a value of type T using the given visitor.
Note that this method is not forwards compatible with new variants from the API, unless visitor overrides Visitor.unknown. To handle variants not known to this version of the SDK gracefully, consider overriding Visitor.unknown:
import com.openai.core.JsonValue; import java.util.Optional; Optional<String> result = tool.accept(new Tool.Visitor<Optional<String>>() { @Override public Optional<String> visitFunction(FunctionTool function) { return Optional.of(function.toString()); } // ... @Override public Optional<String> unknown(JsonValue json) { // Or inspect the `json`. return Optional.empty(); } });
-
validate
final Tool validate()
Validates that the types of all values in this object match their expected types recursively.
This method is not forwards compatible with new types from the API for existing fields.
-
ofFunction
final static Tool ofFunction(FunctionTool function)
Defines a function in your own code the model can choose to call. Learn more about function calling.
-
ofFileSearch
final static Tool ofFileSearch(FileSearchTool fileSearch)
A tool that searches for relevant content from uploaded files. Learn more about the file search tool.
-
ofComputer
final static Tool ofComputer(ComputerTool computer)
A tool that controls a virtual computer. Learn more about the computer tool.
-
ofComputerUsePreview
final static Tool ofComputerUsePreview(ComputerUsePreviewTool computerUsePreview)
A tool that controls a virtual computer. Learn more about the computer tool.
-
ofWebSearch
final static Tool ofWebSearch(WebSearchTool webSearch)
Search the Internet for sources related to the prompt. Learn more about the web search tool.
-
ofMcp
final static Tool ofMcp(Tool.Mcp mcp)
Give the model access to additional tools via remote Model Context Protocol (MCP) servers. Learn more about MCP.
-
ofCodeInterpreter
final static Tool ofCodeInterpreter(Tool.CodeInterpreter codeInterpreter)
A tool that runs Python code to help generate a response to a prompt.
-
ofImageGeneration
final static Tool ofImageGeneration(Tool.ImageGeneration imageGeneration)
A tool that generates images using the GPT image models.
-
ofLocalShell
final static Tool ofLocalShell()
A tool that allows the model to execute shell commands in a local environment.
-
ofShell
final static Tool ofShell(FunctionShellTool shell)
A tool that allows the model to execute shell commands.
-
ofCustom
final static Tool ofCustom(CustomTool custom)
A custom tool that processes input using a specified format. Learn more about custom tools
-
ofNamespace
final static Tool ofNamespace(NamespaceTool namespace)
Groups function/custom tools under a shared namespace.
-
ofSearch
final static Tool ofSearch(ToolSearchTool search)
Hosted or BYOT tool search configuration for deferred tools.
-
ofWebSearchPreview
final static Tool ofWebSearchPreview(WebSearchPreviewTool webSearchPreview)
This tool searches the web for relevant results to use in a response. Learn more about the web search tool.
-
ofApplyPatch
final static Tool ofApplyPatch(ApplyPatchTool applyPatch)
Allows the assistant to create, delete, or update files using unified diffs.
-
-
-
-