langchain_core.utils.function_calling.convert_to_openai_tool

langchain_core.utils.function_calling.convert_to_openai_tool(tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]) Dict[str, Any][source]

Convert a raw function/class to an OpenAI tool.

Parameters

tool (Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]) – Either a dictionary, a pydantic.BaseModel class, Python function, or BaseTool. If a dictionary is passed in, it is assumed to already be a valid OpenAI tool, OpenAI function, or a JSON schema with top-level ‘title’ and ‘description’ keys specified.

Returns

A dict version of the passed in tool which is compatible with the

OpenAI tool-calling API.

Return type

Dict[str, Any]

Examples using convert_to_openai_tool